wolfcw / libfaketime

libfaketime modifies the system time for a single application
https://github.com/wolfcw/libfaketime
GNU General Public License v2.0
2.64k stars 321 forks source link

libfaketime.c: wrap timespec_get in TIME_UTC macro #415

Closed usertam closed 1 year ago

usertam commented 1 year ago

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.


This PR is motivated by errors I faced when building on x86_64-darwin:

libfaketime.c:2345:29: error: use of undeclared identifier 'timespec_get'
  DONT_FAKE_TIME(result = (*timespec_get)(ts, base));
                            ^
libfaketime.c:4022:38: error: use of undeclared identifier 'timespec_get'
  DYLD_INTERPOSE(macos_timespec_get, timespec_get);
                                     ^

Typing the error into google yielded this: 1, then I got more information and came up with this by looking at others' bits. 2 4

wolfcw commented 1 year ago

Thanks for catching this and the PR!