Skip to content

Commit

Permalink
posix.time: predicate clock_getres et.al. on _POSIX_TIMERS.
Browse files Browse the repository at this point in the history
Close #295.
musl libc implements clock_getres and clock_gettime, and defines
_POSIX_TIMERS, but does not declare _XOPEN_REALTIME because it
does not implement the whole realtime API.
* lukefile (modules['posix.time'].libraries): Use _POSIX_TIMERS,
which is a subset of _XOPEN_REALTIME sufficient for clock_getres
and clock_gettime in the host libc.
* ext/posix/time.c (CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID)
(CLOCK_REALTIME, Pclock_getres, Pclock_gettime): Change preprocessor
guards from _XOPEN_REALTIME to _POSIX_TIMERS.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
  • Loading branch information
gvvaughan committed Jan 27, 2018
1 parent 7fa5a20 commit ba00056
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions ext/posix/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pushtm(lua_State *L, struct tm *t)
}


#if defined _XOPEN_REALTIME && _XOPEN_REALTIME != -1
#if defined _POSIX_TIMERS
/***
Find the precision of a clock.
@function clock_getres
Expand Down Expand Up @@ -326,7 +326,7 @@ Ptime(lua_State *L)

static const luaL_Reg posix_time_fns[] =
{
#if defined _XOPEN_REALTIME && _XOPEN_REALTIME != -1
#if defined _POSIX_TIMERS
LPOSIX_FUNC( Pclock_getres ),
LPOSIX_FUNC( Pclock_gettime ),
#endif
Expand All @@ -348,7 +348,7 @@ luaopen_posix_time(lua_State *L)
lua_pushstring(L, LPOSIX_VERSION_STRING("time"));
lua_setfield(L, -2, "version");

#if defined _XOPEN_REALTIME && _XOPEN_REALTIME != -1
#if defined _POSIX_TIMERS
LPOSIX_CONST( CLOCK_MONOTONIC );
LPOSIX_CONST( CLOCK_PROCESS_CPUTIME_ID );
LPOSIX_CONST( CLOCK_REALTIME );
Expand Down
2 changes: 1 addition & 1 deletion lukefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ modules = {
['posix.time'] = {
libraries = {
{
ifdef = '_XOPEN_REALTIME',
ifdef = '_POSIX_TIMERS',
include = 'unistd.h',
checksymbol = 'clock_gettime',
library = 'rt',
Expand Down

0 comments on commit ba00056

Please sign in to comment.