Date: Thu, 30 Jan 2003 14:15:52 +0200 (EET) From: Adrian Penisoara <ady@freebsd.ady.ro> To: standards@freebsd.org Subject: strftime(): FreeBSD vs. Linux Message-ID: <Pine.BSF.4.10.10301301357001.46520-100000@ady.warpnet.ro>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.10.10301301357001.46520-100000>