f09289b08fc89d7e3686726265dcf8fd1ef3a73e
[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_GETPID && HAVE__GETPID
88 #define getpid _getpid
89 #endif /* !HAVE_GETPID && HAVE__GETPID */
90
91 #if !HAVE_DECL_LOCALTIME_R
92 #if !defined(localtime_r)
93 CK_DLL_EXP struct tm *localtime_r (const time_t * clock, struct tm *result);
94 #endif
95 #endif /* !HAVE_DECL_LOCALTIME_R */
96
97 #if !HAVE_DECL_STRDUP && !HAVE__STRDUP
98 CK_DLL_EXP char *strdup (const char *str);
99 #elif !HAVE_DECL_STRDUP && HAVE__STRDUP
100 #define strdup _strdup
101 #endif /* !HAVE_DECL_STRDUP && HAVE__STRDUP */
102
103 #if !HAVE_DECL_STRSIGNAL
104 CK_DLL_EXP char *strsignal (int sig);
105 #endif /* !HAVE_DECL_STRSIGNAL */
106
107 /*
108  * On systems where clock_gettime() is not available, or
109  * on systems where some clocks may not be supported, the
110  * definition for CLOCK_MONOTONIC and CLOCK_REALTIME may not
111  * be available. These should define which type of clock
112  * clock_gettime() should use. We define it here if it is
113  * not defined simply so the reimplementation can ignore it.
114  *
115  * We set the values of these clocks to some (hopefully)
116  * invalid value, to avoid the case where we define a
117  * clock with a valid value, and unintentionally use
118  * an actual good clock by accident.
119  */
120 #ifndef CLOCK_MONOTONIC
121 #define CLOCK_MONOTONIC -1
122 #endif
123 #ifndef CLOCK_REALTIME
124 #define CLOCK_REALTIME -1
125 #endif
126
127 #ifndef HAVE_LIBRT
128
129 #ifdef STRUCT_TIMESPEC_DEFINITION_MISSING
130 /*
131  * The following structure is defined in POSIX 1003.1 for times
132  * specified in seconds and nanoseconds. If it is not defined in
133  * time.g, then we need to define it here
134  */
135 struct timespec
136 {
137   time_t tv_sec;
138   long tv_nsec;
139 };
140 #endif /* STRUCT_TIMESPEC_DEFINITION_MISSING */
141
142 #ifdef STRUCT_ITIMERSPEC_DEFINITION_MISSING
143 /* 
144  * The following structure is defined in POSIX.1b for timer start values and intervals.
145  * If it is not defined in time.h, then we need to define it here.
146  */
147 struct itimerspec
148 {
149   struct timespec it_interval;
150   struct timespec it_value;
151 };
152 #endif /* STRUCT_ITIMERSPEC_DEFINITION_MISSING */
153
154 /* 
155  * Do a simple forward declaration in case the struct is not defined.
156  * In the versions of timer_create in libcompat, sigevent is never
157  * used.
158  */
159 struct sigevent;
160
161 #ifndef HAVE_CLOCK_GETTIME
162 CK_DLL_EXP int clock_gettime (clockid_t clk_id, struct timespec *ts);
163 #endif
164 CK_DLL_EXP int timer_create (clockid_t clockid, struct sigevent *sevp,
165     timer_t * timerid);
166 CK_DLL_EXP int timer_settime (timer_t timerid, int flags,
167     const struct itimerspec *new_value, struct itimerspec *old_value);
168 CK_DLL_EXP int timer_delete (timer_t timerid);
169 #endif /* HAVE_LIBRT */
170
171 /* silence warnings about an empty library */
172 CK_DLL_EXP void
173 ck_do_nothing (void)
174     CK_ATTRIBUTE_NORETURN;
175
176 #endif /* !LIBCOMPAT_H */