gettimeofday.c

00001 /* $Id: gettimeofday.c,v 1.1 2006/11/20 13:38:01 tho Exp $ */
00002 
00003 #include <u/libu_conf.h>
00004 
00005 #ifndef HAVE_GETTIMEOFDAY
00006 #include <toolbox/carpal.h>
00007 #include <missing/gettimeofday.h>
00008 
00009 #ifdef OS_WIN
00010 #include <time.h>
00011 #include <sys/timeb.h>
00012 int gettimeofday(struct timeval *tv, struct timezone *tz)
00013 {
00014     struct _timeb tb;
00015 
00016     dbg_return_if(tv == NULL, -1);
00017 
00018     /* get current time */
00019     _ftime(&tb);
00020 
00021     /* set the timeval struct */
00022     tv->tv_sec = tb.time;
00023     tv->tv_usec = 1000 * tb.millitm;
00024 
00025     if(tz == NULL)
00026         return 0;
00027 
00028     /* set the tiemzone struct */
00029     tz->tz_minuteswest = tb.timezone;
00030     tz->tz_dsttime = tb.dstflag;
00031 
00032     return 0;
00033 }
00034 #else
00035 #warning missing gettimeofday,tv.tv_usec will be always set to zero
00036 int gettimeofday(struct timeval *tv, struct timezone *tzp)
00037 {
00038         if(tzp)
00039                 tzp->tz_minuteswest = tzp->tz_dsttime = 0;
00040 
00041         tv->tv_sec = time(0);
00042         tv->tv_usec = 0;
00043 
00044         return 0;
00045 }
00046 #endif
00047 
00048 #else
00049 #include <sys/time.h>
00050 int gettimeofday(struct timeval *tp, struct timezone *tzp);
00051 #endif  /* !HAVE_GETTIMEOFDAY */

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