Skip to content

Commit 10fd9f6

Browse files
Richard Oliverblp
Richard Oliver
authored andcommitted
timeval: Check for OS-provided clock_gettime on macOS
[Problem] Compilation error on newer versions of macOS (Sierra onwards) due to multiple declarations of clock_gettime. [Solution] Have configure check for clock_gettime and check this result in timeval to avoid incorrectly declaring/defining clock_gettime again. [Testing] Source code now successfully builds on macOS. Signed-off-by: Richard Oliver <[email protected]> Signed-off-by: Ben Pfaff <[email protected]>
1 parent 45a9c31 commit 10fd9f6

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

AUTHORS.rst

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ Raymond Burkholder [email protected]
263263
264264
Remko Tronçon [email protected]
265265
266+
Richard Oliver [email protected]
266267
Rishi Bamba [email protected]
267268
268269
Robert Åkerblom-Andersson [email protected]

configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ AC_CHECK_MEMBERS([struct mmsghdr.msg_len], [], [], [[#include <sys/socket.h>]])
112112
AC_CHECK_MEMBERS([struct sockaddr_in6.sin6_scope_id], [], [],
113113
[[#include <sys/socket.h>
114114
#include <netinet/in.h>]])
115-
AC_CHECK_FUNCS([mlockall strnlen getloadavg statvfs getmntent_r sendmmsg])
115+
AC_CHECK_FUNCS([mlockall strnlen getloadavg statvfs getmntent_r sendmmsg clock_gettime])
116116
AC_CHECK_HEADERS([mntent.h sys/statvfs.h linux/types.h linux/if_ether.h stdatomic.h])
117117
AC_CHECK_HEADERS([net/if_mib.h], [], [], [[#include <sys/types.h>
118118
#include <net/if.h>]])

lib/timeval.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
VLOG_DEFINE_THIS_MODULE(timeval);
4343

44-
#if defined(_WIN32) || defined(__MACH__)
44+
#if !defined(HAVE_CLOCK_GETTIME)
4545
typedef unsigned int clockid_t;
4646
static int clock_gettime(clock_t id, struct timespec *ts);
4747

@@ -52,7 +52,7 @@ static int clock_gettime(clock_t id, struct timespec *ts);
5252
#ifndef CLOCK_REALTIME
5353
#define CLOCK_REALTIME 2
5454
#endif
55-
#endif /* defined(_WIN32) || defined(__MACH__) */
55+
#endif /* !defined(HAVE_CLOCK_GETTIME) */
5656

5757
#ifdef _WIN32
5858
/* Number of 100 ns intervals from January 1, 1601 till January 1, 1970. */
@@ -453,7 +453,7 @@ clock_gettime(clock_t id, struct timespec *ts)
453453
}
454454
#endif /* _WIN32 */
455455

456-
#ifdef __MACH__
456+
#if defined(__MACH__) && !defined(HAVE_CLOCK_GETTIME)
457457
#include <mach/clock.h>
458458
#include <mach/mach.h>
459459
static int

0 commit comments

Comments
 (0)