Skip to content

Commit

Permalink
Implement timespec_get
Browse files Browse the repository at this point in the history
  • Loading branch information
catap authored and cjones051073 committed Sep 23, 2022
1 parent 03a02c1 commit bce12af
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ Wrapped headers and replaced functions are:
</tr>
<tr>
<td><code>time.h</code></td>
<td>Adds <code>clock_gettime</code> function (macOS10.11). Declares <code>asctime_r</code>, <code>ctime_r</code>, <code>gmtime_r</code>, and <code>localtime_r</code> functions that are otherwise hidden in the presence of <code>_ANSI_SOURCE</code>, <code>_POSIX_C_SOURCE</code>, or <code>_XOPEN_SOURCE</code> (OSX10.4)</td>
<td>OSX10.4(11)</td>
<td>Adds functions <code>clock_gettime</code>(macOS10.11) and <code>timespec_get</code>(macOS10.14). Defines <code>TIME_UTC</code> (macOS10.14). Declares <code>asctime_r</code>, <code>ctime_r</code>, <code>gmtime_r</code>, and <code>localtime_r</code> functions that are otherwise hidden in the presence of <code>_ANSI_SOURCE</code>, <code>_POSIX_C_SOURCE</code>, or <code>_XOPEN_SOURCE</code> (OSX10.4)</td>
<td>OSX10.4(11,14)</td>
</tr>
<tr>
<td><code>wchar.h</code></td>
Expand Down
3 changes: 3 additions & 0 deletions include/MacportsLegacySupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
/* clock_gettime */
#define __MP_LEGACY_SUPPORT_GETTIME__ (__APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200)

/* timespec_get */
#define __MP_LEGACY_SUPPORT_TIMESPEC_GET__ (__APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500)

/* **at calls */
#define __MP_LEGACY_SUPPORT_ATCALLS__ (__APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101000)

Expand Down
15 changes: 15 additions & 0 deletions include/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,19 @@ __MP__END_DECLS

#endif /* _MP_LEGACY_SUPPORT_GETTIME__ */

/* Legacy implementation of timespec */
#if __MP_LEGACY_SUPPORT_TIMESPEC_GET__

#ifndef TIME_UTC
#define TIME_UTC 1 /* time elapsed since epoch */
#endif

__MP__BEGIN_DECLS

extern int timespec_get(struct timespec *ts, int base);

__MP__END_DECLS

#endif /* __MP_LEGACY_SUPPORT_TIMESPEC_GET__ */

#endif /* _MACPORTS_TIME_H_ */
18 changes: 18 additions & 0 deletions src/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,21 @@ int clock_gettime( int clk_id, struct timespec *ts )
*/

#endif

#if __MP_LEGACY_SUPPORT_TIMESPEC_GET__

int timespec_get(struct timespec *ts, int base)
{
switch (base) {
case TIME_UTC:
if (clock_gettime(CLOCK_REALTIME, ts) == -1)
return 0;

return base;

default:
return 0;
}
}

#endif

0 comments on commit bce12af

Please sign in to comment.