8 #if defined(__GNUC__) && defined(__GNUC_MINOR__)
9 #define GCC_VERSION_AT_LEAST(major, minor) \
10 ((__GNUC__ > (major)) || \
11 (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
13 #define GCC_VERSION_AT_LEAST(major, minor) 0
16 #if GCC_VERSION_AT_LEAST(2,95)
17 #define CK_ATTRIBUTE_UNUSED __attribute__ ((unused))
19 #define CK_ATTRIBUTE_UNUSED
22 #if GCC_VERSION_AT_LEAST(2,5)
23 #define CK_ATTRIBUTE_NORETURN __attribute__ ((noreturn))
25 #define CK_ATTRIBUTE_NORETURN
29 * Used for MSVC to create the export attribute
30 * CK_DLL_EXP is defined during the compilation of the library
31 * on the command line.
38 #include <WinSock2.h> /* struct timeval, API used in gettimeofday implementation */
39 #include <io.h> /* read, write */
40 #include <process.h> /* getpid */
44 #include <sys/types.h>
55 /* provides localtime and struct tm */
56 #ifdef HAVE_SYS_TIME_H
58 #endif /* !HAVE_SYS_TIME_H */
61 /* declares fork(), _POSIX_VERSION. according to Autoconf.info,
62 unistd.h defines _POSIX_VERSION if the system is POSIX-compliant,
63 so we will use this as a test for all things uniquely provided by
64 POSIX like sigaction() and fork() */
69 #ifdef HAVE_SYS_WAIT_H
73 /* declares pthread_create and friends */
82 /* replacement functions for broken originals */
84 CK_DLL_EXP unsigned int alarm (unsigned int seconds);
85 #endif /* !HAVE_DECL_ALARM */
88 CK_DLL_EXP void *rpl_malloc (size_t n);
89 #endif /* !HAVE_MALLOC */
92 CK_DLL_EXP void *rpl_realloc (void *p, size_t n);
93 #endif /* !HAVE_REALLOC */
95 #if !HAVE_GETPID && HAVE__GETPID
96 #define getpid _getpid
97 #endif /* !HAVE_GETPID && HAVE__GETPID */
99 #if !HAVE_GETTIMEOFDAY
100 CK_DLL_EXP int gettimeofday (struct timeval *tv, void *tz);
101 #endif /* !HAVE_GETTIMEOFDAY */
103 #if !HAVE_DECL_LOCALTIME_R
104 #if !defined(localtime_r)
105 CK_DLL_EXP struct tm *localtime_r (const time_t * clock, struct tm *result);
107 #endif /* !HAVE_DECL_LOCALTIME_R */
109 #if !HAVE_DECL_STRDUP && !HAVE__STRDUP
110 CK_DLL_EXP char *strdup (const char *str);
111 #elif !HAVE_DECL_STRDUP && HAVE__STRDUP
112 #define strdup _strdup
113 #endif /* !HAVE_DECL_STRDUP && HAVE__STRDUP */
115 #if !HAVE_DECL_STRSIGNAL
116 CK_DLL_EXP const char *strsignal (int sig);
117 #endif /* !HAVE_DECL_STRSIGNAL */
120 * On systems where clock_gettime() is not available, or
121 * on systems where some clocks may not be supported, the
122 * definition for CLOCK_MONOTONIC and CLOCK_REALTIME may not
123 * be available. These should define which type of clock
124 * clock_gettime() should use. We define it here if it is
125 * not defined simply so the reimplementation can ignore it.
127 * We set the values of these clocks to some (hopefully)
128 * invalid value, to avoid the case where we define a
129 * clock with a valid value, and unintentionally use
130 * an actual good clock by accident.
132 #ifndef CLOCK_MONOTONIC
133 #define CLOCK_MONOTONIC -1
135 #ifndef CLOCK_REALTIME
136 #define CLOCK_REALTIME -1
141 #ifdef STRUCT_TIMESPEC_DEFINITION_MISSING
143 * The following structure is defined in POSIX 1003.1 for times
144 * specified in seconds and nanoseconds. If it is not defined in
145 * time.g, then we need to define it here
152 #endif /* STRUCT_TIMESPEC_DEFINITION_MISSING */
154 #ifdef STRUCT_ITIMERSPEC_DEFINITION_MISSING
156 * The following structure is defined in POSIX.1b for timer start values and intervals.
157 * If it is not defined in time.h, then we need to define it here.
161 struct timespec it_interval;
162 struct timespec it_value;
164 #endif /* STRUCT_ITIMERSPEC_DEFINITION_MISSING */
167 * Do a simple forward declaration in case the struct is not defined.
168 * In the versions of timer_create in libcompat, sigevent is never
173 CK_DLL_EXP int clock_gettime (clockid_t clk_id, struct timespec *ts);
174 CK_DLL_EXP int timer_create (clockid_t clockid, struct sigevent *sevp,
176 CK_DLL_EXP int timer_settime (timer_t timerid, int flags,
177 const struct itimerspec *new_value, struct itimerspec *old_value);
178 CK_DLL_EXP int timer_delete (timer_t timerid);
179 #endif /* HAVE_LIBRT */
182 * The following checks are to determine if the system's
183 * snprintf (or its variants) should be replaced with
184 * the C99 compliant version in libcompat.
193 CK_DLL_EXP int rpl_vsnprintf (char *, size_t, const char *, va_list);
195 #define vsnprintf rpl_vsnprintf
198 CK_DLL_EXP int rpl_snprintf (char *, size_t, const char *, ...);
200 #define snprintf rpl_snprintf
202 #endif /* HAVE_STDARG_H */
205 CK_DLL_EXP ssize_t getline (char **lineptr, size_t * n, FILE * stream);
208 /* silence warnings about an empty library */
211 CK_ATTRIBUTE_NORETURN;
213 #endif /* !LIBCOMPAT_H */