Try to clean up the compat stuff a bit

This commit is contained in:
Oliver Jowett 2020-08-07 15:08:45 +08:00
parent 74e11bd26f
commit 286a6301f8
5 changed files with 29 additions and 65 deletions

View File

@ -58,8 +58,8 @@
* *
*/ */
#include "../compat.h"
#include "clock_gettime.h" #include <mach/mach_time.h>
#include <mach/clock.h> // for clock_get_time #include <mach/clock.h> // for clock_get_time
#include <mach/clock_types.h> // for mach_timespec_t, CALENDAR_CLOCK, etc #include <mach/clock_types.h> // for mach_timespec_t, CALENDAR_CLOCK, etc
#include <mach/kern_return.h> // for KERN_SUCCESS, kern_return_t #include <mach/kern_return.h> // for KERN_SUCCESS, kern_return_t
@ -70,6 +70,8 @@
#include <errno.h> // for EINVAL, errno #include <errno.h> // for EINVAL, errno
#include <unistd.h> // for getpid #include <unistd.h> // for getpid
static mach_timebase_info_data_t __clock_gettime_inf;
int clock_gettime(clockid_t clk_id, struct timespec *tp) int clock_gettime(clockid_t clk_id, struct timespec *tp)
{ {
kern_return_t ret; kern_return_t ret;

View File

@ -1,35 +1,6 @@
#ifndef CLOCK_GETTIME_H #ifndef CLOCK_GETTIME_H
#define CLOCK_GETTIME_H #define CLOCK_GETTIME_H
#include <mach/mach_time.h> // Apple-only, but this isn't inclued on other BSDs
#ifdef __OpenBSD__
#ifdef _CLOCKID_T_DEFINED_
#define CLOCKID_T
#endif
#endif
#ifdef __APPLE__
#ifdef CLOCK_MONOTONIC
#define CLOCKID_T
#endif
#endif
#ifndef CLOCKID_T
#define CLOCKID_T
typedef enum
{
CLOCK_REALTIME,
CLOCK_MONOTONIC,
CLOCK_PROCESS_CPUTIME_ID,
CLOCK_THREAD_CPUTIME_ID
} clockid_t;
#endif // ifndef CLOCKID_T
struct timespec;
static mach_timebase_info_data_t __clock_gettime_inf;
int clock_gettime(clockid_t clk_id, struct timespec *tp); int clock_gettime(clockid_t clk_id, struct timespec *tp);
#endif // CLOCK_GETTIME_H #endif // CLOCK_GETTIME_H

View File

@ -22,10 +22,7 @@
#include <errno.h> // for errno, EINVAL #include <errno.h> // for errno, EINVAL
#include <time.h> // for nanosleep, NULL #include <time.h> // for nanosleep, NULL
#include "clock_nanosleep.h" #include "../compat.h"
#ifdef MISSING_GETTIME
#include "../clock_gettime/clock_gettime.h" // for clock_gettime
#endif
int clock_nanosleep(clockid_t id, int flags, const struct timespec *ts, int clock_nanosleep(clockid_t id, int flags, const struct timespec *ts,
struct timespec *ots) { struct timespec *ots) {

View File

@ -1,36 +1,6 @@
#ifndef CLOCK_NANOSLEEP_H #ifndef CLOCK_NANOSLEEP_H
#define CLOCK_NANOSLEEP_H #define CLOCK_NANOSLEEP_H
#ifdef __OpenBSD__
#ifdef _CLOCKID_T_DEFINED_
#define CLOCKID_T
#endif
#endif
#ifdef __APPLE__
#ifdef CLOCK_MONOTONIC
#define CLOCKID_T
#endif
#endif
#ifndef CLOCKID_T
#define CLOCKID_T
typedef enum
{
CLOCK_REALTIME,
CLOCK_MONOTONIC,
CLOCK_PROCESS_CPUTIME_ID,
CLOCK_THREAD_CPUTIME_ID
} clockid_t;
#endif // ifndef CLOCKID_T
#ifndef TIMER_ABSTIME
#define TIMER_ABSTIME 1
#endif // TIMER_ABSTIME
struct timespec;
int clock_nanosleep (clockid_t id, int flags, const struct timespec *ts, int clock_nanosleep (clockid_t id, int flags, const struct timespec *ts,
struct timespec *ots); struct timespec *ots);

View File

@ -28,6 +28,30 @@
#endif #endif
/* clock_* and time-related types */
#include <time.h>
#if defined(CLOCK_REALTIME)
# define HAVE_CLOCKID_T
#endif
#ifndef HAVE_CLOCKID_T
typedef enum
{
CLOCK_REALTIME,
CLOCK_MONOTONIC,
CLOCK_PROCESS_CPUTIME_ID,
CLOCK_THREAD_CPUTIME_ID
} clockid_t;
#endif // !HAVE_CLOCKID_T
#ifndef TIMER_ABSTIME
#define TIMER_ABSTIME 1
#endif // !TIMER_ABSTIME
struct timespec;
#ifdef MISSING_NANOSLEEP #ifdef MISSING_NANOSLEEP
#include "clock_nanosleep/clock_nanosleep.h" #include "clock_nanosleep/clock_nanosleep.h"
#endif #endif