From owner-freebsd-hackers@FreeBSD.ORG Fri Apr 1 08:15:51 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C8A0316A4CE for ; Fri, 1 Apr 2005 08:15:51 +0000 (GMT) Received: from marlena.vvi.at (marlena.vvi.at [208.252.225.59]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5908B43D46 for ; Fri, 1 Apr 2005 08:15:51 +0000 (GMT) (envelope-from www@marlena.vvi.at) Received: from marlena.vvi.at (localhost.marlena.vvi.at [127.0.0.1]) by marlena.vvi.at (8.12.10/8.12.9) with ESMTP id j318G2h3037435; Fri, 1 Apr 2005 00:16:03 -0800 (PST) (envelope-from www@marlena.vvi.at) Received: (from www@localhost) by marlena.vvi.at (8.12.10/8.12.10/Submit) id j318FtcY037434; Fri, 1 Apr 2005 00:15:55 -0800 (PST) (envelope-from www) Date: Fri, 1 Apr 2005 00:15:55 -0800 (PST) Message-Id: <200504010815.j318FtcY037434@marlena.vvi.at> To: ganbold@micom.mng.net From: "ALeine" cc: freebsd-hackers@freebsd.org Subject: Re: subtracting days from localtime problem X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Apr 2005 08:15:51 -0000 ganbold@micom.mng.net wrote: > One more question, what will happen next time when > time goes back in October? > Does following line correct it as same as now? > > /* make mktime(3) figure out whether DST is in effect */ > t->tm_isdst = -1; Yes, it will work correctly. You can see what happens by setting now to 1131131131 (where you currently have now = time(NULL)). It's not an April Fools' Day joke, that just happens to be an appropriate time in November. :-) I also noticed a number of bugs in your code that you may want to fix: - memory leak: you are allocating memory with my_alloc(), but then you neither free(3) it nor keep track of it. You should remove my_alloc() and just create a buffer in main() and then pass it by reference to functions that need to modify its contents. - with my_alloc() you basically reinvented strdup(3), see man 3 strdup for details. You do not need strdup(3) for what you want to achieve, just pass the buffer from main() by reference and then use snprintf(3) to modify its contents. - snprintf(3) handles the size argument correctly, meaning that you should specify the full size of the string since at most size-1 characters are written with guaranteed NULL termination, see man 3 snprintf for details. ALeine ___________________________________________________________________ WebMail FREE http://mail.austrosearch.net