libreplace: add clock_gettime replacement function for systems that don't have it
authorBjörn Jacke <bj@sernet.de>
Thu, 19 Aug 2010 17:07:04 +0000 (19:07 +0200)
committerBjörn Jacke <bj@sernet.de>
Tue, 31 Aug 2010 07:07:29 +0000 (09:07 +0200)
lib/replace/README
lib/replace/replace.c
lib/replace/replace.h
lib/replace/system/time.h

index b2d2e4fea53952f72db3296b7f87732da5529967..bf4e67ff0c9911608111cec98d244d6997c6e670 100644 (file)
@@ -33,6 +33,7 @@ opendir
 readdir
 telldir
 seekdir
+clock_gettime
 closedir
 dlopen
 dlclose
index 12716ea6d339936e259500b67c00ab9735580da3..f3459dd9c2b95932f2e3216f1a4b86f54ae49b73 100644 (file)
@@ -760,3 +760,24 @@ int rep_strerror_r(int errnum, char *buf, size_t buflen)
        return 0;
 }
 #endif
+
+#ifndef HAVE_CLOCK_GETTIME
+int rep_clock_gettime(clockid_t clk_id, struct timespec *tp)
+{
+       struct timeval tval;
+       switch (clk_id) {
+               case 0: /* CLOCK_REALTIME :*/
+#ifdef HAVE_GETTIMEOFDAY_TZ
+                       gettimeofday(&tval,NULL);
+#else
+                       gettimeofday(&tval);
+#endif
+                       tp->tv_sec = tval.tv_sec;
+                       tp->tv_nsec = tval.tv_usec * 1000;
+                       break;
+               default:
+                       return EINVAL;
+       }
+       return 0;
+}
+#endif
index 4efcb4c6ee215bd09d5088ffdf095add04a3b4dc..055dd7172f70203f979046ad8284b7411a498754 100644 (file)
@@ -517,6 +517,10 @@ char *rep_get_current_dir_name(void);
 int rep_strerror_r(int errnum, char *buf, size_t buflen);
 #endif
 
+#if !defined(HAVE_CLOCK_GETTIME)
+#define clock_gettime rep_clock_gettime
+#endif
+
 #ifdef HAVE_LIMITS_H
 #include <limits.h>
 #endif
index 4abf295d1af819af2992e50f65355a690f122d84..ff26531e45b8d4b179056e659799f8ceb25227e4 100644 (file)
@@ -66,4 +66,10 @@ int rep_utime(const char *filename, const struct utimbuf *buf);
 int rep_utimes(const char *filename, const struct timeval tv[2]);
 #endif
 
+#ifndef HAVE_CLOCK_GETTIME
+#define CLOCK_REALTIME 0
+typedef int clockid_t;
+int rep_clock_gettime(clockid_t clk_id, struct timespec *tp);
+#endif
+
 #endif