diff options
author | Samuel Tam <heiyiutam@gmail.com> | 2022-12-20 00:35:53 +0800 |
---|---|---|
committer | usertam <heiyiutam@gmail.com> | 2022-12-20 02:08:45 +0800 |
commit | e0e6b79568d36a8fd2b3c41f7214769221182128 (patch) | |
tree | b2c242e33441b86fd397821783386696123b5e0f /src | |
parent | df8a04559743c9de6fbad0e8279ee69ea09b914c (diff) | |
download | libfaketime-e0e6b79568d36a8fd2b3c41f7214769221182128.tar.gz |
libfaketime.c: wrap timespec_get in TIME_UTC macro
Function `timespec_get` is not guaranteed to be declared in MacOS
since its standard library is non-conformance to modern standards.
Therefore, skip patching `timespec_get` if it is undeclared by the
standard library.
The detection of `timespec_get` is based on the conjecture that the
macro `TIME_UTC` is only defined when `timespec_get` is declared.
Diffstat (limited to 'src')
-rw-r--r-- | src/libfaketime.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libfaketime.c b/src/libfaketime.c index b5b0fe2..e3d4b47 100644 --- a/src/libfaketime.c +++ b/src/libfaketime.c @@ -196,7 +196,9 @@ 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); +#ifdef TIME_UTC static int (*real_timespec_get) (struct timespec *ts, int base); +#endif #ifdef FAKE_INTERNAL_CALLS static int (*real___ftime) (struct timeb *); static int (*real___gettimeofday) (struct timeval *, void *); @@ -2441,6 +2443,7 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp) } +#ifdef TIME_UTC #ifdef MACOS_DYLD_INTERPOSE int macos_timespec_get(struct timespec *ts, int base) #else @@ -2475,6 +2478,7 @@ int timespec_get(struct timespec *ts, int base) /* return the result to the caller */ return result; } +#endif /* @@ -2681,7 +2685,9 @@ static void ftpl_init(void) real_lxstat64 = dlsym(RTLD_NEXT, "__lxstat64"); real_time = dlsym(RTLD_NEXT, "time"); real_ftime = dlsym(RTLD_NEXT, "ftime"); +#ifdef TIME_UTC real_timespec_get = dlsym(RTLD_NEXT, "timespec_get"); +#endif #ifdef FAKE_FILE_TIMESTAMPS real_utimes = dlsym(RTLD_NEXT, "utimes"); real_utime = dlsym(RTLD_NEXT, "utime"); @@ -4163,7 +4169,9 @@ void do_macos_dyld_interpose(void) { DYLD_INTERPOSE(macos_nanosleep, nanosleep); DYLD_INTERPOSE(macos_poll, poll); #endif +#ifdef TIME_UTC DYLD_INTERPOSE(macos_timespec_get, timespec_get); +#endif DYLD_INTERPOSE(macos_select, select); #ifdef FAKE_RANDOM DYLD_INTERPOSE(macos_getentropy, getentropy); |