| 1 |
|
| 2 |
/* |
| 3 |
* Copyright (c) 2018 Chris Jones <[email protected]> |
| 4 |
* |
| 5 |
* Permission to use, copy, modify, and distribute this software for any |
| 6 |
* purpose with or without fee is hereby granted, provided that the above |
| 7 |
* copyright notice and this permission notice appear in all copies. |
| 8 |
* |
| 9 |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 12 |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 14 |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 |
*/ |
| 17 |
|
| 18 |
#ifndef _MACPORTS_TIME_H_ |
| 19 |
#define _MACPORTS_TIME_H_ |
| 20 |
|
| 21 |
/* MP support header */ |
| 22 |
#include "MacportsLegacySupport.h" |
| 23 |
|
| 24 |
/* Include the primary system time.h */ |
| 25 |
#include_next <time.h> |
| 26 |
|
| 27 |
/* The following functions are implemented by Tiger, but the declarations are |
| 28 |
* missing if _ANSI_SOURCE or _POSIX_C_SOURCE are defined, which occurs when |
| 29 |
* _XOPEN_SOURCE is set. */ |
| 30 |
#if __MP_LEGACY_SUPPORT_TIME_THREAD_SAFE_FUNCTIONS__ |
| 31 |
|
| 32 |
__MP__BEGIN_DECLS |
| 33 |
#if defined(_ANSI_SOURCE) || defined(_POSIX_C_SOURCE) |
| 34 |
char *asctime_r(const struct tm *, char *); |
| 35 |
char *ctime_r(const time_t *, char *); |
| 36 |
struct tm *gmtime_r(const time_t *, struct tm *); |
| 37 |
struct tm *localtime_r(const time_t *, struct tm *); |
| 38 |
#endif /* defined(_ANSI_SOURCE) || defined(_POSIX_C_SOURCE) */ |
| 39 |
__MP__END_DECLS |
| 40 |
|
| 41 |
#endif /* __MP_LEGACY_SUPPORT_TIME_THREAD_SAFE_FUNCTIONS__ */ |
| 42 |
|
| 43 |
/* Legacy implementation of clock_gettime */ |
| 44 |
#if __MP_LEGACY_SUPPORT_GETTIME__ |
| 45 |
|
| 46 |
/* One define types and methods if not already defined. */ |
| 47 |
#if !defined(CLOCK_REALTIME) && !defined(CLOCK_MONOTONIC) |
| 48 |
typedef int clockid_t; |
| 49 |
#endif /* !defined(CLOCK_REALTIME) && !defined(CLOCK_MONOTONIC) */ |
| 50 |
|
| 51 |
#ifndef CLOCK_REALTIME |
| 52 |
#define CLOCK_REALTIME 0 |
| 53 |
#endif |
| 54 |
#ifndef CLOCK_MONOTONIC |
| 55 |
#define CLOCK_MONOTONIC 6 |
| 56 |
#endif |
| 57 |
|
| 58 |
#ifndef CLOCK_MONOTONIC_RAW |
| 59 |
#define CLOCK_MONOTONIC_RAW 4 |
| 60 |
#endif |
| 61 |
#ifndef CLOCK_MONOTONIC_RAW_APPROX |
| 62 |
#define CLOCK_MONOTONIC_RAW_APPROX 5 |
| 63 |
#endif |
| 64 |
|
| 65 |
#ifndef CLOCK_UPTIME_RAW |
| 66 |
#define CLOCK_UPTIME_RAW 8 |
| 67 |
#endif |
| 68 |
|
| 69 |
#ifndef CLOCK_UPTIME_RAW_APPROX |
| 70 |
#define CLOCK_UPTIME_RAW_APPROX 8 |
| 71 |
#endif |
| 72 |
|
| 73 |
#ifndef CLOCK_PROCESS_CPUTIME_ID |
| 74 |
#define CLOCK_PROCESS_CPUTIME_ID 12 |
| 75 |
#endif |
| 76 |
|
| 77 |
#ifndef CLOCK_THREAD_CPUTIME_ID |
| 78 |
#define CLOCK_THREAD_CPUTIME_ID 16 |
| 79 |
#endif |
| 80 |
|
| 81 |
__MP__BEGIN_DECLS |
| 82 |
|
| 83 |
extern int clock_gettime( clockid_t clk_id, struct timespec *ts ); |
| 84 |
extern int clock_getres ( clockid_t clk_id, struct timespec *ts ); |
| 85 |
|
| 86 |
__MP__END_DECLS |
| 87 |
|
| 88 |
#endif /* __MP_LEGACY_SUPPORT_GETTIME__ */ |
| 89 |
|
| 90 |
/* Legacy implementation of timespec */ |
| 91 |
#if __MP_LEGACY_SUPPORT_TIMESPEC_GET__ |
| 92 |
|
| 93 |
#ifndef TIME_UTC |
| 94 |
#define TIME_UTC 1 /* time elapsed since epoch */ |
| 95 |
#endif |
| 96 |
|
| 97 |
__MP__BEGIN_DECLS |
| 98 |
|
| 99 |
extern int timespec_get(struct timespec *ts, int base); |
| 100 |
|
| 101 |
__MP__END_DECLS |
| 102 |
|
| 103 |
#endif /* __MP_LEGACY_SUPPORT_TIMESPEC_GET__ */ |
| 104 |
|
| 105 |
#endif /* _MACPORTS_TIME_H_ */ |