check: Import version 0.9.14
[platform/upstream/gstreamer.git] / libs / gst / check / libcheck / libcompat.h
1 #ifndef LIBCOMPAT_H
2 #define LIBCOMPAT_H
3
4 #if HAVE_CONFIG_H
5 #include <config.h>
6 #endif
7
8 #if defined(__GNUC__) && defined(__GNUC_MINOR__)
9 #define GCC_VERSION_AT_LEAST(major, minor) \
10 ((__GNUC__ > (major)) || \
11  (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
12 #else
13 #define GCC_VERSION_AT_LEAST(major, minor) 0
14 #endif
15
16 #if GCC_VERSION_AT_LEAST(2,95)
17 #define CK_ATTRIBUTE_UNUSED __attribute__ ((unused))
18 #else
19 #define CK_ATTRIBUTE_UNUSED
20 #endif /* GCC 2.95 */
21
22 #if GCC_VERSION_AT_LEAST(2,5)
23 #define CK_ATTRIBUTE_NORETURN __attribute__ ((noreturn))
24 #else
25 #define CK_ATTRIBUTE_NORETURN
26 #endif /* GCC 2.5 */
27
28 /*
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.
32  */
33 #ifndef CK_DLL_EXP
34 #define CK_DLL_EXP
35 #endif
36
37 #if _MSC_VER
38 #include <WinSock2.h>           /* struct timeval, API used in gettimeofday implementation */
39 #include <io.h>                 /* read, write */
40 #include <process.h>            /* getpid */
41 #endif /* _MSC_VER */
42
43 /* defines size_t */
44 #include <sys/types.h>
45
46 /* provides assert */
47 #include <assert.h>
48
49 /* defines FILE */
50 #include <stdio.h>
51
52 /* defines exit() */
53 #include <stdlib.h>
54
55 /* provides localtime and struct tm */
56 #ifdef HAVE_SYS_TIME_H
57 #include <sys/time.h>
58 #endif /* !HAVE_SYS_TIME_H */
59 #include <time.h>
60
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() */
65 #ifdef HAVE_UNISTD_H
66 #include <unistd.h>
67 #endif
68
69 #ifdef HAVE_SYS_WAIT_H
70 #include <sys/wait.h>
71 #endif
72
73 /* declares pthread_create and friends */
74 #ifdef HAVE_PTHREAD
75 #include <pthread.h>
76 #endif
77
78 #ifdef HAVE_STDINT_H
79 #include <stdint.h>
80 #endif
81
82 /* replacement functions for broken originals */
83 #if !HAVE_DECL_ALARM
84 CK_DLL_EXP unsigned int alarm (unsigned int seconds);
85 #endif /* !HAVE_DECL_ALARM */
86
87 #if !HAVE_MALLOC
88 CK_DLL_EXP void *rpl_malloc (size_t n);
89 #endif /* !HAVE_MALLOC */
90
91 #if !HAVE_REALLOC
92 CK_DLL_EXP void *rpl_realloc (void *p, size_t n);
93 #endif /* !HAVE_REALLOC */
94
95 #if !HAVE_GETPID && HAVE__GETPID
96 #define getpid _getpid
97 #endif /* !HAVE_GETPID && HAVE__GETPID */
98
99 #if !HAVE_GETTIMEOFDAY
100 CK_DLL_EXP int gettimeofday (struct timeval *tv, void *tz);
101 #endif /* !HAVE_GETTIMEOFDAY */
102
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);
106 #endif
107 #endif /* !HAVE_DECL_LOCALTIME_R */
108
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 */
114
115 #if !HAVE_DECL_STRSIGNAL
116 CK_DLL_EXP const char *strsignal (int sig);
117 #endif /* !HAVE_DECL_STRSIGNAL */
118
119 /*
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.
126  *
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.
131  */
132 #ifndef CLOCK_MONOTONIC
133 #define CLOCK_MONOTONIC -1
134 #endif
135 #ifndef CLOCK_REALTIME
136 #define CLOCK_REALTIME -1
137 #endif
138
139 #ifndef HAVE_LIBRT
140
141 #ifdef STRUCT_TIMESPEC_DEFINITION_MISSING
142 /*
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
146  */
147 struct timespec
148 {
149   time_t tv_sec;
150   long tv_nsec;
151 };
152 #endif /* STRUCT_TIMESPEC_DEFINITION_MISSING */
153
154 #ifdef STRUCT_ITIMERSPEC_DEFINITION_MISSING
155 /* 
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.
158  */
159 struct itimerspec
160 {
161   struct timespec it_interval;
162   struct timespec it_value;
163 };
164 #endif /* STRUCT_ITIMERSPEC_DEFINITION_MISSING */
165
166 /* 
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
169  * used.
170  */
171 struct sigevent;
172
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,
175     timer_t * timerid);
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 */
180
181 /*
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.
185  */
186 #if HAVE_CONFIG_H
187 #include <config.h>
188 #endif
189 #if HAVE_STDARG_H
190 #include <stdarg.h>
191
192 #if !HAVE_VSNPRINTF
193 CK_DLL_EXP int rpl_vsnprintf (char *, size_t, const char *, va_list);
194
195 #define vsnprintf rpl_vsnprintf
196 #endif
197 #if !HAVE_SNPRINTF
198 CK_DLL_EXP int rpl_snprintf (char *, size_t, const char *, ...);
199
200 #define snprintf rpl_snprintf
201 #endif
202 #endif /* HAVE_STDARG_H */
203
204 #if !HAVE_GETLINE
205 CK_DLL_EXP ssize_t getline (char **lineptr, size_t * n, FILE * stream);
206 #endif
207
208 /* silence warnings about an empty library */
209 CK_DLL_EXP void
210 ck_do_nothing (void)
211     CK_ATTRIBUTE_NORETURN;
212
213 #endif /* !LIBCOMPAT_H */