This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/5184] strftime stats /etc/localtime too much
- From: "jakub at redhat dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 16 Oct 2007 08:13:46 -0000
- Subject: [Bug libc/5184] strftime stats /etc/localtime too much
- References: <20071016022504.5184.adi@hexapodia.org>
- Reply-to: sourceware-bugzilla at sourceware dot org
------- Additional Comments From jakub at redhat dot com 2007-10-16 08:13 -------
I think the complaint in this case is that strftime, instead of doing tzset
just once, does it 5 times.
#include <time.h>
#define DBG(str) write (-1, str, sizeof (str) - 1)
int
main (void)
{
char buf[40];
time_t now;
struct tm *tmp;
now = time (0);
tmp = localtime (&now);
strftime (buf, sizeof (buf), "%F %T", tmp);
DBG ("before time");
now = time (0);
DBG ("before localtime");
tmp = localtime (&now);
DBG ("before strftime");
strftime (buf, sizeof (buf), "%F %T", tmp);
DBG ("after strftime");
return 0;
}
strace ./Y # against CVS glibc
...
write(4294967295, "before time", 11) = -1 EBADF (Bad file descriptor)
write(4294967295, "before localtime", 16) = -1 EBADF (Bad file descriptor)
write(4294967295, "before strftime", 15) = -1 EBADF (Bad file descriptor)
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2246, ...}) = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2246, ...}) = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2246, ...}) = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2246, ...}) = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2246, ...}) = 0
write(4294967295, "after strftime", 14) = -1 EBADF (Bad file descriptor)
That is IMHO easily fixable with some rearrangments of strftime_l.c - changing
the my_strftime function to an an internal helper with an additional argument,
writing a tiny wrapper and not calling tzset () if it has been called already by
an outer strftime in case of recursion.
BTW, doesn't localtime have to stat /etc/localtime?
http://www.opengroup.org/onlinepubs/009695399/functions/localtime.html
Local timezone information is used as though localtime() calls tzset().
--
http://sourceware.org/bugzilla/show_bug.cgi?id=5184
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.