diff --git a/README.md b/README.md
index 7746098..18c0d7a 100644
--- a/README.md
+++ b/README.md
@@ -85,8 +85,8 @@ Wrapped headers and replaced functions are:
time.h |
- Adds clock_gettime function (macOS10.11). Declares asctime_r , ctime_r , gmtime_r , and localtime_r functions that are otherwise hidden in the presence of _ANSI_SOURCE , _POSIX_C_SOURCE , or _XOPEN_SOURCE (OSX10.4) |
- OSX10.4(11) |
+ Adds functions clock_gettime (macOS10.11) and timespec_get (macOS10.14). Defines TIME_UTC (macOS10.14). Declares asctime_r , ctime_r , gmtime_r , and localtime_r functions that are otherwise hidden in the presence of _ANSI_SOURCE , _POSIX_C_SOURCE , or _XOPEN_SOURCE (OSX10.4) |
+ OSX10.4(11,14) |
wchar.h |
diff --git a/include/MacportsLegacySupport.h b/include/MacportsLegacySupport.h
index 09b0e8e..4e0c4ee 100644
--- a/include/MacportsLegacySupport.h
+++ b/include/MacportsLegacySupport.h
@@ -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)
diff --git a/include/time.h b/include/time.h
index 8cbd86b..5ea5974 100644
--- a/include/time.h
+++ b/include/time.h
@@ -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_ */
diff --git a/src/time.c b/src/time.c
index 0e92654..bda2743 100644
--- a/src/time.c
+++ b/src/time.c
@@ -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