time: better autodetection on win32
authorMarko Kreen <markokr@gmail.com>
Thu, 5 May 2011 18:23:02 +0000 (21:23 +0300)
committerMarko Kreen <markokr@gmail.com>
Thu, 5 May 2011 18:23:02 +0000 (21:23 +0300)
Seems like the posix functions are slowly added to mingw/msvcrt
so we cannot blindly assume with #ifdef WIN32 whats there.

Add proper autodetection for gettimeofday(), localtime_r(), getrusage()

Remove double detection for recvmsg and sendmsg.

m4/usual.m4
usual/time.c
usual/time.h

index 7cea9f39155e695a072bf77690200c2da27137aa..481d87895bfafc95b342116d261ec4c21a701099 100644 (file)
@@ -184,9 +184,9 @@ AC_CHECK_FUNCS(posix_memalign memalign valloc)
 AC_CHECK_FUNCS(getopt getopt_long getopt_long_only)
 AC_CHECK_FUNCS(fls flsl flsll ffs ffsl ffsll)
 ### Functions provided only on win32
-AC_CHECK_FUNCS(localtime_r recvmsg sendmsg usleep)
+AC_CHECK_FUNCS(localtime_r gettimeofday recvmsg sendmsg usleep getrusage)
 ### Functions used by libusual itself
-AC_CHECK_FUNCS(syslog mmap recvmsg sendmsg getpeerucred)
+AC_CHECK_FUNCS(syslog mmap getpeerucred)
 ### win32: link with ws2_32
 AC_SEARCH_LIBS(WSAGetLastError, ws2_32)
 AC_FUNC_STRERROR_R
index 2e2a5a84ecf4486afd2fef1ca765827a81f9e9bd..7d33201a5a7c97597cd743904639728ac712e35c 100644 (file)
@@ -106,6 +106,8 @@ static void ft2tv(FILETIME *src, struct timeval *dst, bool use_epoch)
        dst->tv_usec = (tmp.QuadPart % FT_SEC) / 10;
 }
 
+#ifndef HAVE_GETTIMEOFDAY
+
 int gettimeofday(struct timeval * tp, void * tzp)
 {
        FILETIME file_time;
@@ -121,6 +123,10 @@ int gettimeofday(struct timeval * tp, void * tzp)
        return 0;
 }
 
+#endif /* !HAVE_GETTIMEOFDAY */
+
+#ifndef HAVE_LOCALTIME_R
+
 struct tm *localtime_r(const time_t *tp, struct tm *dst)
 {
        ULARGE_INTEGER utc;
@@ -151,6 +157,10 @@ struct tm *localtime_r(const time_t *tp, struct tm *dst)
        return dst;
 }
 
+#endif /* !HAVE_LOCALTIME_R */
+
+#ifndef HAVE_GETRUSAGE
+
 int getrusage(int who, struct rusage *dst)
 {
        FILETIME tcreate, texit, tkern, tuser;
@@ -165,4 +175,6 @@ int getrusage(int who, struct rusage *dst)
        return 0;
 }
 
-#endif
+#endif /* !HAVE_GETRUSAGE */
+
+#endif /* WIN32 */
index 6a8f28e24165acdb553ebe80afdbcd0de8d0acf6..0911b4adac86e0ae317c8dee66e5d51ebbd0a420 100644 (file)
@@ -49,26 +49,49 @@ usec_t get_cached_time(void);
 void reset_time_cache(void);
 
 #ifdef WIN32
+
+
+#ifndef HAVE_GETTIMEOFDAY
+#define gettimeofday(t,z) usual_gettimeofday(t,z)
+
 /** Compat: gettimeofday() */
 int gettimeofday(struct timeval * tp, void * tzp);
+
+#endif
+
+
+#ifndef HAVE_LOCALTIME_R
+#define localtime_r(t,b) usual_localtime_r(t,b)
+
 /** Compat: localtime_r() */
 struct tm *localtime_r(const time_t *tp, struct tm *buf);
 
+#endif
+
 #ifndef HAVE_USLEEP
+#define usleep(x) usual_usleep(x)
+
 /** Compat: usleep() */
 static inline void usleep(long usec) { Sleep(usec / 1000); }
+
 #endif
 
+#ifndef HAVE_GETRUSAGE
+#define getrusage(w,d) usual_getrusage(w,d)
+
+#define RUSAGE_SELF 0
+
 /** Compat: rusage for win32 */
 struct rusage {
        struct timeval ru_utime;
        struct timeval ru_stime;
 };
 
-#define RUSAGE_SELF 0
 /** Compat: getrusage() for win32 */
 int getrusage(int who, struct rusage *dst);
 
 #endif
 
 #endif
+
+#endif