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