timegm.c

00001 /* $Id: timegm.c,v 1.1 2006/11/20 13:38:01 tho Exp $ */
00002 
00003 #include <u/libu_conf.h>
00004 #include <time.h>
00005 
00006 #ifndef HAVE_TIMEGM
00007 
00008 #include <stdlib.h>
00009 #include <stdio.h>
00010 
00011 time_t timegm(struct tm *tm)
00012 {
00013     time_t ret;
00014     char *tz;
00015     
00016     /* save current timezone and set UTC */
00017     tz = getenv("TZ");
00018     putenv("TZ=UTC");   /* use Coordinated Universal Time (i.e. zero offset) */
00019     tzset();
00020     
00021     ret = mktime(tm);
00022     if(tz)
00023     {
00024         char buf[256];
00025         snprintf(buf, sizeof(buf), "TZ=%s", tz);
00026         putenv(buf);
00027     } else
00028         putenv("TZ=");
00029     tzset();
00030     
00031     return ret;
00032 }
00033 
00034 #else
00035 time_t timegm(struct tm*);
00036 #endif 

←Products
© 2005-2012 - KoanLogic S.r.l. - All rights reserved