[Gelistirici] Fwd: mktime + UTC problem
S.Çağlar Onur
caglar at pardus.org.tr
6 Kas 2006 Pzt 17:11:38 EET
Gürer bize rapor edilen sorunda benzer miydi?
---------- Yönlendirilmiş İleti ----------
Subject: mktime + UTC problem
Date: 06 Kas 2006 Pts 16:00
From: Daniel Drake <ddrake at brontes3d.com>
To: libc-alpha at sourceware.org
Hi,
I'm trying to diagnose a problem where hwclock is restoring an incorrect
time from my hardware clock. I have traced this down to mktime() not
behaving as described.
In this context, hwclock is dealing with a UTC time value in a tm
structure. It then tries to convert this to UTC seconds from the epoch
using setenv("TZ", "", 1); tzset(); then mktime(). However, the
seconds-from-epoch value being returned here is wrong.
I have reproduced this in a small stand-alone test program:
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main(void)
{
struct tm tm;
setenv("TZ", "", 1);
tzset();
memset(&tm, 0, sizeof(tm));
tm.tm_sec = 0;
tm.tm_min = 0;
tm.tm_hour = 18;
tm.tm_mday = 3;
tm.tm_mon = 10;
tm.tm_year = 106;
tm.tm_yday = -1;
tm.tm_isdst = 0;
time_t ret = mktime(&tm);
printf("ret %ld\n", ret);
ret = timegm(&tm);
printf("ret %ld\n", ret);
}
The above program attempts to interpret the tm time as UTC using
mktime(), then does the same with timegm().
On a normal system, this should output:
1162576800
1162576800
On this one system, I get:
1162594800
1162576800
timegm() is doing as it should but mktime() is not. I note that the
timegm man page has a code snippet for mktime very similar to what I am
using above.
Interestingly enough if I change:
setenv("TZ", "", 1);
to:
setenv("TZ", "GMT0", 1);
then the test program produces the expected results.
Am I missing something, or does this look like a bug?
Thanks!
Daniel
-------------------------------------------------------
--
S.Çağlar Onur <caglar at pardus.org.tr>
http://cekirdek.pardus.org.tr/~caglar/
Linux is like living in a teepee. No Windows, no Gates and an Apache in house!
-------------- sonraki bölüm --------------
A non-text attachment was scrubbed...
Name: kullanılamıyor
Type: application/pgp-signature
Size: 189 bytes
Desc: kullanılamıyor
URL: <http://liste.pardus.org.tr/gelistirici/attachments/20061106/d9ddc04f/attachment-0002.pgp>
Gelistirici mesaj listesiyle ilgili
daha fazla bilgi