Debian Codegraph @

libs/gst/check/libcheck/libcompat/libcompat.h

raw
1 /*
2 * Check: a unit test framework for C
3 * Copyright (C) 2001, 2002 Arien Malec
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
18 * MA 02110-1301, USA.
19 */
20
21 #ifndef LIBCOMPAT_H
22 #define LIBCOMPAT_H
23
24 #if HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #if defined(__GNUC__) && defined(__GNUC_MINOR__)
29 #define GCC_VERSION_AT_LEAST(major, minor) \
30 ((__GNUC__ > (major)) || \
31 (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
32 #else
33 #define GCC_VERSION_AT_LEAST(major, minor) 0
34 #endif
35
36 #if GCC_VERSION_AT_LEAST(2,95)
37 #define CK_ATTRIBUTE_UNUSED __attribute__ ((unused))
38 #else
39 #define CK_ATTRIBUTE_UNUSED
40 #endif /* GCC 2.95 */
41
42 #if GCC_VERSION_AT_LEAST(2,5)
43 #define CK_ATTRIBUTE_NORETURN __attribute__ ((noreturn))
44 #else
45 #define CK_ATTRIBUTE_NORETURN
46 #endif /* GCC 2.5 */
47
48 /*
49 * Used for MSVC to create the export attribute
50 * CK_DLL_EXP is defined during the compilation of the library
51 * on the command line.
52 */
53 #ifndef CK_DLL_EXP
54 #define CK_DLL_EXP extern
55 #endif
56
57 #ifdef _MSC_VER
58 #include <WinSock2.h> /* struct timeval, API used in gettimeofday implementation */
59 #include <io.h> /* read, write */
60 #include <BaseTsd.h> /* for ssize_t */
61 #include <processthreadsapi.h> /* GetCurrentProcessId */
62 /* getpid() is not allowed in case of UWP, use GetCurrentProcessId() instead
63 * which can be used on both desktop and UWP */
64 #define getpid GetCurrentProcessId
65 typedef SSIZE_T ssize_t;
66 #endif /* _MSC_VER */
67
68 /* defines size_t */
69 #include <sys/types.h>
70
71 /* provides assert */
72 #include <assert.h>
73
74 /* defines FILE */
75 #include <stdio.h>
76
77 /* defines exit() */
78 #include <stdlib.h>
79
80 /* provides localtime and struct tm */
81 #ifdef HAVE_SYS_TIME_H
82 #include <sys/time.h>
83 #endif /* !HAVE_SYS_TIME_H */
84 #include <time.h>
85
86 /* declares fork(), _POSIX_VERSION. according to Autoconf.info,
87 unistd.h defines _POSIX_VERSION if the system is POSIX-compliant,
88 so we will use this as a test for all things uniquely provided by
89 POSIX like sigaction() and fork() */
90 #ifdef HAVE_UNISTD_H
91 #include <unistd.h>
92 #endif
93
94 #ifdef HAVE_SYS_WAIT_H
95 #include <sys/wait.h>
96 #endif
97
98 /* declares pthread_create and friends */
99 #ifdef HAVE_PTHREAD
100 #include <pthread.h>
101 #endif
102
103 #ifdef HAVE_STDINT_H
104 #include <stdint.h>
105 #endif
106
107 /* replacement functions for broken originals */
108 #if !HAVE_DECL_ALARM
109 CK_DLL_EXP unsigned int alarm (unsigned int seconds);
110 #endif /* !HAVE_DECL_ALARM */
111
112 #if !HAVE_MALLOC
113 CK_DLL_EXP void *rpl_malloc (size_t n);
114 #endif /* !HAVE_MALLOC */
115
116 #if !HAVE_REALLOC
117 CK_DLL_EXP void *rpl_realloc (void *p, size_t n);
118 #endif /* !HAVE_REALLOC */
119
120 #if !HAVE_GETPID && HAVE__GETPID && !defined(_MSC_VER)
121 #define getpid _getpid
122 #endif /* !HAVE_GETPID && HAVE__GETPID */
123
124 #if !HAVE_GETTIMEOFDAY
125 CK_DLL_EXP int gettimeofday (struct timeval *tv, void *tz);
126 #endif /* !HAVE_GETTIMEOFDAY */
127
128 #if !HAVE_DECL_LOCALTIME_R
129 #if !defined(localtime_r)
130 CK_DLL_EXP struct tm *localtime_r (const time_t * clock, struct tm *result);
131 #endif
132 #endif /* !HAVE_DECL_LOCALTIME_R */
133
134 #if !HAVE_DECL_STRDUP && !HAVE__STRDUP
135 CK_DLL_EXP char *strdup (const char *str);
136 #elif !HAVE_DECL_STRDUP && HAVE__STRDUP
137 #define strdup _strdup
138 #endif /* !HAVE_DECL_STRDUP && HAVE__STRDUP */
139
140 #if !HAVE_DECL_STRSIGNAL
141 CK_DLL_EXP char *strsignal (int sig);
142 #endif /* !HAVE_DECL_STRSIGNAL */
143
144 /*
145 * On systems where clock_gettime() is not available, or
146 * on systems where some clocks may not be supported, the
147 * definition for CLOCK_MONOTONIC and CLOCK_REALTIME may not
148 * be available. These should define which type of clock
149 * clock_gettime() should use. We define it here if it is
150 * not defined simply so the reimplementation can ignore it.
151 *
152 * We set the values of these clocks to some (hopefully)
153 * invalid value, to avoid the case where we define a
154 * clock with a valid value, and unintentionally use
155 * an actual good clock by accident.
156 */
157 #ifndef CLOCK_MONOTONIC
158 #define CLOCK_MONOTONIC -1
159 #endif
160 #ifndef CLOCK_REALTIME
161 #define CLOCK_REALTIME -1
162 #endif
163
164 #ifndef HAVE_LIBRT
165
166 #ifdef STRUCT_TIMESPEC_DEFINITION_MISSING
167 /*
168 * The following structure is defined in POSIX 1003.1 for times
169 * specified in seconds and nanoseconds. If it is not defined in
170 * time.g, then we need to define it here
171 */
172 struct timespec
173 {
174 time_t tv_sec;
175 long tv_nsec;
176 };
177 #endif /* STRUCT_TIMESPEC_DEFINITION_MISSING */
178
179 #ifdef STRUCT_ITIMERSPEC_DEFINITION_MISSING
180 /*
181 * The following structure is defined in POSIX.1b for timer start values and intervals.
182 * If it is not defined in time.h, then we need to define it here.
183 */
184 struct itimerspec
185 {
186 struct timespec it_interval;
187 struct timespec it_value;
188 };
189 #endif /* STRUCT_ITIMERSPEC_DEFINITION_MISSING */
190
191 /*
192 * Do a simple forward declaration in case the struct is not defined.
193 * In the versions of timer_create in libcompat, sigevent is never
194 * used.
195 */
196 struct sigevent;
197
198 #ifndef HAVE_CLOCK_GETTIME
199 CK_DLL_EXP int clock_gettime (clockid_t clk_id, struct timespec *ts);
200 #endif
201 CK_DLL_EXP int timer_create (clockid_t clockid, struct sigevent *sevp,
202 timer_t * timerid);
203 CK_DLL_EXP int timer_settime (timer_t timerid, int flags,
204 const struct itimerspec *new_value, struct itimerspec *old_value);
205 CK_DLL_EXP int timer_delete (timer_t timerid);
206 #endif /* HAVE_LIBRT */
207
208 /*
209 * The following checks are to determine if the system's
210 * snprintf (or its variants) should be replaced with
211 * the C99 compliant version in libcompat.
212 */
213 #if HAVE_CONFIG_H
214 #include <config.h>
215 #endif
216 #if HAVE_STDARG_H
217 #include <stdarg.h>
218
219 #if !HAVE_VSNPRINTF
220 CK_DLL_EXP int rpl_vsnprintf (char *, size_t, const char *, va_list);
221
222 #define vsnprintf rpl_vsnprintf
223 #endif
224 #if !HAVE_SNPRINTF
225 CK_DLL_EXP int rpl_snprintf (char *, size_t, const char *, ...);
226
227 #define snprintf rpl_snprintf
228 #endif
229 #endif /* HAVE_STDARG_H */
230
231 #if !HAVE_GETLINE
232 CK_DLL_EXP ssize_t getline (char **lineptr, size_t * n, FILE * stream);
233 #endif
234
235 /* silence warnings about an empty library */
236 CK_DLL_EXP void
237 ck_do_nothing (void)
238 CK_ATTRIBUTE_NORETURN;
239
240 #endif /* !LIBCOMPAT_H */