]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
Add clock_gettime compat shim.
authorDarren Tucker <dtucker@dtucker.net>
Tue, 7 Oct 2025 09:04:40 +0000 (20:04 +1100)
committerDarren Tucker <dtucker@dtucker.net>
Tue, 7 Oct 2025 09:04:40 +0000 (20:04 +1100)
This fixes the build on macOS prior to 10.12 Sierra, since it does not
have it.  Found and tested by Sevan Janiyan.

openbsd-compat/bsd-misc.c
openbsd-compat/bsd-misc.h

index 983cd3fe6216407b8e327f057b03cb8270077170..2c196ec23eee1070cf7334522971e9d9c8f3d6d4 100644 (file)
@@ -494,6 +494,30 @@ localtime_r(const time_t *timep, struct tm *result)
 }
 #endif
 
+#ifndef HAVE_CLOCK_GETTIME
+int
+clock_gettime(clockid_t clockid, struct timespec *ts)
+{
+       struct timeval tv;
+
+       if (clockid != CLOCK_REALTIME) {
+               errno = ENOSYS;
+               return -1;
+       }
+       if (ts == NULL) {
+               errno = EFAULT;
+               return -1;
+       }
+
+       if (gettimeofday(&tv, NULL) == -1)
+               return -1;
+
+       ts->tv_sec = tv.tv_sec;
+       ts->tv_nsec = (long)tv.tv_usec * 1000;
+       return 0;
+}
+#endif
+
 #ifdef ASAN_OPTIONS
 const char *__asan_default_options(void) {
        return ASAN_OPTIONS;
index 2ad89cd83b5958748721fe5fe9a6e30f15fa20f6..8495f471c285ab50cd7f99f90ea08ffba6f3ead6 100644 (file)
@@ -202,6 +202,14 @@ int flock(int, int);
 struct tm *localtime_r(const time_t *, struct tm *);
 #endif
 
+#ifndef HAVE_CLOCK_GETTIME
+typedef int clockid_t;
+#ifndef CLOCK_REALTIME
+# define CLOCK_REALTIME        0
+#endif
+int clock_gettime(clockid_t, struct timespec *);
+#endif
+
 #ifndef HAVE_REALPATH
 #define realpath(x, y) (sftp_realpath((x), (y)))
 #endif