faketime: fake a bit more to pass compilation on Solaris 11
/*
- * Copyright 2013-2019 Fabian Groffen
+ * Copyright 2013-2020 Fabian Groffen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
# error must have dlsym/RTLD_NEXT to fake time
#endif
-#include <dlfcn.h>
#if 0
/* we cannot include time.h and sys/time.h due to gettimeofday
* definition being different on some platforms with
#include <time.h>
#include <sys/time.h>
#else
+#define _TIME_H
+#define _SYS_TIME_H
/* internal definition, we only access tv_sec so don't care about the
* type/definition of tv_usec */
#if SIZEOF_TIME_T == 4
-#define time_t int
+#define fttime_t int
#elif SIZEOF_TIME_T == 8
-#define time_t long long int
+#define fttime_t long long int
#else
-#define time_t ssize_t
+#define fttime_t ssize_t
#endif
-struct timeval {
- time_t tv_sec;
+struct fttimeval {
+ fttime_t tv_sec;
};
#define NULL (void *)0
#endif
+#include <dlfcn.h>
+
/* for repeatability, always return time starting from 1981-02-01 from the
* first call to time(). This way we can control the aggregator time
* buckets */
#define MYEPOCH 349830000
-time_t (*orig_time)(time_t *tloc) = NULL;
-int (*orig_gettimeofday)(struct timeval *tp, void *tz) = NULL;
-time_t fake_offset = 0;
+fttime_t (*orig_time)(fttime_t *tloc) = NULL;
+int (*orig_gettimeofday)(struct fttimeval *tp, void *tz) = NULL;
+fttime_t fake_offset = 0;
__attribute__((constructor)) void init(void) {
orig_time = dlsym(RTLD_NEXT, "time");
orig_gettimeofday = dlsym(RTLD_NEXT, "gettimeofday");
}
-time_t time(time_t *tloc) {
- time_t now;
+fttime_t time(fttime_t *tloc) {
+ fttime_t now;
(void)orig_time(&now);
@@ -74,11 +77,11 @@ time_t time(time_t *tloc) {
return now;
}
-int gettimeofday(struct timeval *tp, void *tzp) {
+int gettimeofday(struct fttimeval *tp, void *tzp) {
/* some platforms, like Darwin and Solaris, have an implementation
* of gettimeofday that does not call time(), others, like glibc do
* which means we need to deal with that here */
- time_t now;
+ fttime_t now;
int ret = orig_gettimeofday(tp, tzp);
if (ret != 0)
