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: "mann at vmware dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 13 Aug 2008 00:22:52 -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 mann at vmware dot com 2008-08-13 00:22 -------
Why is strftime special? If I write a program that repeatedly calls ctime()
and/or localtime(), it reads /etc/localtime only once. But if I call strftime,
it reads /etc/localtime once for each call to strftime. TZ is not set in my
environment. This behavior is inconsistent with the claim that "All the time
functions are required to check TZ all the time. Missing that envvar,
/etc/localtime is used." Surely localtime and ctime are included in the set
"All the time functions."
Reading this file on every call is pretty ugly for programs that write log
messages and include a timestamp on each line formatted using strftime.
I'm using libc 2.6.1-1ubuntu10, from Ubuntu 7.10 on x86_64.
Here's a sample program to demonstrate. Run it with no arguments and it will
open and read /etc/localtime 11 times.
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
int
main(int argc, char **argv)
{
int count = 10, i;
if (argc > 1) {
count = atoi(argv[1]);
}
for (i = 0; i < count; i++) {
time_t now = time(NULL);
printf("%s", ctime(&now));
}
for (i = 0; i < count; i++) {
time_t now = time(NULL);
struct tm ltime;
localtime_r(&now, <ime);
printf("%02u:%02u:%02u\n", ltime.tm_hour, ltime.tm_min, ltime.tm_sec);
}
for (i = 0; i < count; i++) {
time_t now = time(NULL);
struct tm ltime;
char stime[1024];
localtime_r(&now, <ime);
strftime(stime, sizeof(stime), "%H:%M:%S", <ime);
printf("%s\n", stime);
}
}
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|INVALID |
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.