From owner-freebsd-standards Sun Jan 26 2:59:57 2003 Delivered-To: freebsd-standards@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D21A137B401; Sun, 26 Jan 2003 02:59:56 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 742E443F18; Sun, 26 Jan 2003 02:59:56 -0800 (PST) (envelope-from tjr@FreeBSD.org) Received: from freefall.freebsd.org (tjr@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id h0QAxuNS058671; Sun, 26 Jan 2003 02:59:56 -0800 (PST) (envelope-from tjr@freefall.freebsd.org) Received: (from tjr@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id h0QAxt9W058664; Sun, 26 Jan 2003 02:59:55 -0800 (PST) Date: Sun, 26 Jan 2003 02:59:55 -0800 (PST) From: "Tim J. Robbins" Message-Id: <200301261059.h0QAxt9W058664@freefall.freebsd.org> To: tim@robbins.dropbear.id.au, tjr@FreeBSD.org, freebsd-standards@FreeBSD.org Subject: Re: standards/46791: freopen() does not handle filename == NULL correctly Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Synopsis: freopen() does not handle filename == NULL correctly State-Changed-From-To: open->patched State-Changed-By: tjr State-Changed-When: Sun Jan 26 02:58:35 PST 2003 State-Changed-Why: I've implemented this C99 feature as best I can right now. http://www.freebsd.org/cgi/query-pr.cgi?pr=46791 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message From owner-freebsd-standards Sun Jan 26 12:13:36 2003 Delivered-To: freebsd-standards@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7BD6237B401; Sun, 26 Jan 2003 12:13:35 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1F4A543F1E; Sun, 26 Jan 2003 12:13:35 -0800 (PST) (envelope-from alfred@FreeBSD.org) Received: from freefall.freebsd.org (alfred@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id h0QKDZNS008956; Sun, 26 Jan 2003 12:13:35 -0800 (PST) (envelope-from alfred@freefall.freebsd.org) Received: (from alfred@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id h0QKDYAN008952; Sun, 26 Jan 2003 12:13:34 -0800 (PST) Date: Sun, 26 Jan 2003 12:13:34 -0800 (PST) From: Alfred Perlstein Message-Id: <200301262013.h0QKDYAN008952@freefall.freebsd.org> To: rodrigc@attbi.com, alfred@FreeBSD.org, freebsd-standards@FreeBSD.org Subject: Re: standards/47469: Update prototypes to POSIX standard Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Synopsis: Update prototypes to POSIX standard State-Changed-From-To: open->closed State-Changed-By: alfred State-Changed-When: Sun Jan 26 12:13:22 PST 2003 State-Changed-Why: I have committed the delta. http://www.freebsd.org/cgi/query-pr.cgi?pr=47469 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message From owner-freebsd-standards Sun Jan 26 12:14: 2 2003 Delivered-To: freebsd-standards@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 238E037B401; Sun, 26 Jan 2003 12:14:02 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id BD5BA43E4A; Sun, 26 Jan 2003 12:14:01 -0800 (PST) (envelope-from alfred@FreeBSD.org) Received: from freefall.freebsd.org (alfred@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id h0QKE1NS009000; Sun, 26 Jan 2003 12:14:01 -0800 (PST) (envelope-from alfred@freefall.freebsd.org) Received: (from alfred@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id h0QKE1JN008996; Sun, 26 Jan 2003 12:14:01 -0800 (PST) Date: Sun, 26 Jan 2003 12:14:01 -0800 (PST) From: Alfred Perlstein Message-Id: <200301262014.h0QKE1JN008996@freefall.freebsd.org> To: rodrigc@attbi.com, alfred@FreeBSD.org, freebsd-standards@FreeBSD.org Subject: Re: standards/47471: Update to latest POSIX standard Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Synopsis: Update to latest POSIX standard State-Changed-From-To: open->closed State-Changed-By: alfred State-Changed-When: Sun Jan 26 12:13:51 PST 2003 State-Changed-Why: I have committed the delta. http://www.freebsd.org/cgi/query-pr.cgi?pr=47471 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message From owner-freebsd-standards Thu Jan 30 4:17:58 2003 Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 60C4D37B401 for ; Thu, 30 Jan 2003 04:17:57 -0800 (PST) Received: from ady.warpnet.ro (ady.warpnet.ro [217.156.25.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9096643F75 for ; Thu, 30 Jan 2003 04:17:47 -0800 (PST) (envelope-from ady@freebsd.ady.ro) Received: from localhost (ady@localhost) by ady.warpnet.ro (8.9.3/8.9.3) with ESMTP id OAA48440 for ; Thu, 30 Jan 2003 14:15:54 +0200 (EET) (envelope-from ady@freebsd.ady.ro) X-RAV-AntiVirus: This e-mail has been scanned for viruses on host: ady.warpnet.ro Date: Thu, 30 Jan 2003 14:15:52 +0200 (EET) From: Adrian Penisoara X-Sender: ady@ady.warpnet.ro To: standards@freebsd.org Subject: strftime(): FreeBSD vs. Linux Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hi, Recently I had to "backport" a C program written under FreeBSD to Linux and suprisingly I found that the strftime() function behaves different in FreeBSD and Linux: while in FreeBSD strftime() would fill the string buffer with whatever data was specified in the format string up to the specified buffer length, in Linux strftime() would refuse to place the last token specified in the format string if there was not enough space to hold that token and a string terminator (\0). E.g.: #define LEN 12 char buffer[LEN+1]; time_t t=time(NULL); strftime(buffer, LEN, "%b %d %R", localtime(&t)); buffer[LEN] = '\0'; printf("Result: [%s]\n", buffer); This snippet would behave as expected in FreeBSD but not in Linux. In Linux you would need to put LEN+1 as the second argument for strftime(). I find this to be quite disturbing and I wonder which OS steps on the standards. What is the correct behavior ? Thank you, Ady (@freebsd.ady.ro) ____________________________________________________________________ | An age is called Dark not because the light fails to shine, but | | because people refuse to see it. | | -- James Michener, "Space" | To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message From owner-freebsd-standards Thu Jan 30 5: 6:39 2003 Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E481137B401 for ; Thu, 30 Jan 2003 05:06:37 -0800 (PST) Received: from falcon.midgard.homeip.net (h76n3fls20o913.telia.com [213.67.148.76]) by mx1.FreeBSD.org (Postfix) with SMTP id 2054F43F79 for ; Thu, 30 Jan 2003 05:06:34 -0800 (PST) (envelope-from ertr1013@student.uu.se) Received: (qmail 77988 invoked by uid 1001); 30 Jan 2003 13:06:32 -0000 Date: Thu, 30 Jan 2003 14:06:32 +0100 From: Erik Trulsson To: Adrian Penisoara Cc: standards@freebsd.org Subject: Re: strftime(): FreeBSD vs. Linux Message-ID: <20030130130631.GA69654@falcon.midgard.homeip.net> Mail-Followup-To: Adrian Penisoara , standards@freebsd.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.3i Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Thu, Jan 30, 2003 at 02:15:52PM +0200, Adrian Penisoara wrote: > Hi, > > Recently I had to "backport" a C program written under FreeBSD to > Linux and suprisingly I found that the strftime() function behaves > different in FreeBSD and Linux: while in FreeBSD strftime() would fill > the string buffer with whatever data was specified in the format string > up to the specified buffer length, in Linux strftime() would refuse to > place the last token specified in the format string if there was not > enough space to hold that token and a string terminator (\0). > > E.g.: > > #define LEN 12 > char buffer[LEN+1]; > time_t t=time(NULL); > > strftime(buffer, LEN, "%b %d %R", localtime(&t)); > buffer[LEN] = '\0'; > > printf("Result: [%s]\n", buffer); > > This snippet would behave as expected in FreeBSD but not in Linux. In > Linux you would need to put LEN+1 as the second argument for strftime(). > > I find this to be quite disturbing and I wonder which OS steps on the > standards. What is the correct behavior ? I would suggest you check what the return value from strftime is. I suspect in this case it will be 0 for both FreeBSD and Linux, which means that the whole string (including the termintating '\0') didn't fit in the buffer. If strftime returns 0 the contents of the buffer is undefined. (A non-zero return value is the number of characters (not including the terminating '\0') that was but into the buffer. I.e. it is not really working as you expect in FreeBSD either, but you are ignoring the return code that says so. IMO, both systems follow the standard just fine in this case, and the bug is in your code. -- Erik Trulsson ertr1013@student.uu.se To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message From owner-freebsd-standards Thu Jan 30 5:27: 5 2003 Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BB36737B401 for ; Thu, 30 Jan 2003 05:27:03 -0800 (PST) Received: from ady.warpnet.ro (ady.warpnet.ro [217.156.25.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 36DD343F75 for ; Thu, 30 Jan 2003 05:27:02 -0800 (PST) (envelope-from ady@freebsd.ady.ro) Received: from localhost (ady@localhost) by ady.warpnet.ro (8.9.3/8.9.3) with ESMTP id PAA55144; Thu, 30 Jan 2003 15:25:28 +0200 (EET) (envelope-from ady@freebsd.ady.ro) X-RAV-AntiVirus: This e-mail has been scanned for viruses on host: ady.warpnet.ro Date: Thu, 30 Jan 2003 15:25:28 +0200 (EET) From: Adrian Penisoara X-Sender: ady@ady.warpnet.ro To: Erik Trulsson Cc: standards@freebsd.org Subject: Re: strftime(): FreeBSD vs. Linux In-Reply-To: <20030130130631.GA69654@falcon.midgard.homeip.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hi, On Thu, 30 Jan 2003, Erik Trulsson wrote: > On Thu, Jan 30, 2003 at 02:15:52PM +0200, Adrian Penisoara wrote: > > Hi, > > > > Recently I had to "backport" a C program written under FreeBSD to > > Linux and suprisingly I found that the strftime() function behaves > > different in FreeBSD and Linux: while in FreeBSD strftime() would fill > > the string buffer with whatever data was specified in the format string > > up to the specified buffer length, in Linux strftime() would refuse to > > place the last token specified in the format string if there was not > > enough space to hold that token and a string terminator (\0). > > > > E.g.: > > > > #define LEN 12 > > char buffer[LEN+1]; > > time_t t=time(NULL); > > > > strftime(buffer, LEN, "%b %d %R", localtime(&t)); > > buffer[LEN] = '\0'; > > > > printf("Result: [%s]\n", buffer); > > > > This snippet would behave as expected in FreeBSD but not in Linux. In > > Linux you would need to put LEN+1 as the second argument for strftime(). > > > > I find this to be quite disturbing and I wonder which OS steps on the > > standards. What is the correct behavior ? > > I would suggest you check what the return value from strftime is. It's zero both on Linux and FreeBSD. It's 12 both on Linux and FreeBSD when I use LEN+1 as the 2nd argment. > I suspect in this case it will be 0 for both FreeBSD and Linux, which > means that the whole string (including the termintating '\0') didn't > fit in the buffer. If strftime returns 0 the contents of the buffer is > undefined. (A non-zero return value is the number of characters (not > including the terminating '\0') that was but into the buffer. Yep, that's what strftime(2) sais, now that I checked it out. > > I.e. it is not really working as you expect in FreeBSD either, but you are > ignoring the return code that says so. > > > IMO, both systems follow the standard just fine in this case, and the > bug is in your code. Yes, you are right. Next time I should RTFM more closely... :-S. Thanks ! Ady (@warpnet.ro) ____________________________________________________________________ | An age is called Dark not because the light fails to shine, but | | because people refuse to see it. | | -- James Michener, "Space" | To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message