mirror of
https://github.com/wolfcw/libfaketime.git
synced 2026-05-17 00:26:16 +03:00
Merge pull request #487 from ijackson/t64
Fake 64-bit time on 32-bit systems
This commit is contained in:
@@ -164,6 +164,20 @@ struct utimbuf {
|
||||
#include <sys/random.h>
|
||||
#endif
|
||||
|
||||
/* __timespec64 is needed for clock_gettime64 on 32-bit architectures */
|
||||
struct __timespec64
|
||||
{
|
||||
uint64_t tv_sec; /* Seconds */
|
||||
uint32_t tv_nsec; /* this is 32-bit, apparently! */
|
||||
};
|
||||
|
||||
/* __timespec64 is needed for clock_gettime64 on 32-bit architectures */
|
||||
struct __timeval64
|
||||
{
|
||||
uint64_t tv_sec; /* Seconds */
|
||||
uint64_t tv_usec; /* this is 64-bit, apparently! */
|
||||
};
|
||||
|
||||
/*
|
||||
* Per thread variable, which we turn on inside real_* calls to avoid modifying
|
||||
* time multiple times of for the whole process to prevent faking time
|
||||
@@ -201,6 +215,7 @@ static time_t (*real_time) (time_t *);
|
||||
static int (*real_ftime) (struct timeb *);
|
||||
static int (*real_gettimeofday) (struct timeval *, void *);
|
||||
static int (*real_clock_gettime) (clockid_t clk_id, struct timespec *tp);
|
||||
static int (*real_clock_gettime64) (clockid_t clk_id, struct __timespec64 *tp);
|
||||
#ifdef TIME_UTC
|
||||
static int (*real_timespec_get) (struct timespec *ts, int base);
|
||||
#endif
|
||||
@@ -2417,6 +2432,50 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* this is used by 32-bit architectures only */
|
||||
int __clock_gettime64(clockid_t clk_id, struct __timespec64 *tp64)
|
||||
{
|
||||
struct timespec tp;
|
||||
int result;
|
||||
|
||||
result = clock_gettime(clk_id, &tp);
|
||||
tp64->tv_sec = tp.tv_sec;
|
||||
tp64->tv_nsec = tp.tv_nsec;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* this is used by 32-bit architectures only */
|
||||
int __gettimeofday64(struct __timeval64 *tv64, void *tz)
|
||||
{
|
||||
struct timeval tv;
|
||||
int result;
|
||||
|
||||
result = gettimeofday(&tv, tz);
|
||||
tv64->tv_sec = tv.tv_sec;
|
||||
tv64->tv_usec = tv.tv_usec;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* this is used by 32-bit architectures only */
|
||||
uint64_t __time64(uint64_t *write_out)
|
||||
{
|
||||
struct timespec tp;
|
||||
uint64_t output;
|
||||
int error;
|
||||
|
||||
error = clock_gettime(CLOCK_REALTIME, &tp);
|
||||
if (error == -1)
|
||||
{
|
||||
return (uint64_t)error;
|
||||
}
|
||||
output = tp.tv_sec;
|
||||
|
||||
if (write_out)
|
||||
{
|
||||
*write_out = output;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
#ifdef TIME_UTC
|
||||
#ifdef MACOS_DYLD_INTERPOSE
|
||||
@@ -2760,6 +2819,11 @@ static void ftpl_really_init(void)
|
||||
{
|
||||
real_clock_gettime = dlsym(RTLD_NEXT, "clock_gettime");
|
||||
}
|
||||
real_clock_gettime64 = dlsym(RTLD_NEXT, "clock_gettime64");
|
||||
if (NULL == real_clock_gettime64)
|
||||
{
|
||||
real_clock_gettime64 = dlsym(RTLD_NEXT, "__clock_gettime64");
|
||||
}
|
||||
#ifdef FAKE_TIMERS
|
||||
#if defined(__sun)
|
||||
real_timer_gettime_233 = dlsym(RTLD_NEXT, "timer_gettime");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
CC = gcc
|
||||
|
||||
CFLAGS += -std=gnu99 -Wall -DFAKE_STAT -Werror -Wextra $(FAKETIME_COMPILE_CFLAGS)
|
||||
CFLAGS += -std=gnu99 -Wall -DFAKE_STAT -Werror -Wextra $(FAKETIME_COMPILE_CFLAGS) -U_FILE_OFFSET_BITS -U_TIME_BITS
|
||||
LDFLAGS += -lrt -lpthread
|
||||
|
||||
SRC = timetest.c
|
||||
|
||||
Reference in New Issue
Block a user