1 #ifndef _XINE_OS_INTERNAL_H
2 #define _XINE_OS_INTERNAL_H
3 
4 /* When using Apple's GCC, __APPLE__ will be defined.  This is a whole lot of
5  * messiness, but it's necessary in order to perform universal builds properly.
6  * It's meant to over-ride configure time stuff that would be different at
7  * compile time.
8  */
9 #if defined(__APPLE__) && defined(XINE_MACOSX_UNIVERSAL_BINARY)
10 
11 /* __ppc__, __ppc64__, __i386__, __x86_64__ are interesting arch macros */
12 #undef HOST_ARCH
13 #if defined(__ppc__) || defined(__ppc64__)
14 #define ARCH_PPC
15 #if defined(__ppc64__)
16 #define HOST_ARCH           "darwin/powerpc64"
17 #else
18 #define HOST_ARCH           "darwin/powerpc"
19 #endif
20 #elif defined(__i386__) || defined(__x86_64__)
21 #define ARCH_X86
22 #define BITFIELD_LSBF
23 #define HAVE_MMX
24 #if defined(__x86_64__)
25 #define ARCH_X86_64
26 #define HOST_ARCH           "darwin/x86_64"
27 #elif defined(__i386__)
28 #define ARCH_X86_32
29 #define HOST_ARCH           "darwin/x86_32"
30 #else
31 #error unrecognized/unsupported CPU type building for Apple Darwin
32 #endif
33 #endif
34 
35 /* See /Developer/SDKs/MacOSX10.4u.sdk/usr/include/machine/limits.h */
36 #if SIZEOF_INT != 4
37 #undef  SIZEOF_INT
38 #define SIZEOF_INT 4
39 #endif
40 
41 #if defined(__LP64__) && SIZEOF_LONG != 8
42 #undef  SIZEOF_LONG
43 #define SIZEOF_LONG 8
44 #elif !defined(__LP64__) && SIZEOF_LONG != 4
45 #undef  SIZEOF_LONG
46 #define SIZEOF_LONG 4
47 #endif
48 
49 /* WORDS_BIGENDIAN (replaces AC_C_BIGENDIAN autoconf test at compile time) */
50 #include <machine/endian.h>
51 #if BYTE_ORDER == BIG_ENDIAN
52 #define WORDS_BIGENDIAN 1
53 #else
54 #undef  WORDS_BIGENDIAN
55 #endif
56 
57 #if defined(__LP64__)
58 #define FPM_64BIT           1
59 #elif defined(__ppc__) || defined(__ppc64__)
60 #define FPM_PPC             1
61 #elif defined(__i386__) || defined(__x86_64__)
62 #define FPM_INTEL           1
63 #endif
64 
65 #endif  /* __APPLE__ */
66 
67 #include <stddef.h>
68 #include <stdarg.h>
69 
70 #ifdef HAVE_SYS_PARAM_H
71 # include <sys/param.h>
72 #endif
73 
74 #ifdef HOST_OS_DARWIN
75   /* Darwin (Mac OS X) needs __STDC_LIBRARY_SUPPORTED__ for SCNx64 and
76    * SCNxMAX macros */
77 #  ifndef __STDC_LIBRARY_SUPPORTED__
78 #    define __STDC_LIBRARY_SUPPORTED__
79 #  endif /* __STDC_LIBRARY_SUPPORTED__ */
80 #endif
81 
82 #if defined (__SVR4) && defined (__sun)
83 #  include <sys/int_types.h>
84 #endif
85 
86 #include <inttypes.h>
87 #ifndef HAVE_PTHREAD_MUTEX_TIMEDLOCK
88 #include <pthread.h>
89 #endif
90 #include <xine/attributes.h>
91 
92 /* convenience */
93 #define snprintf_buf(buffer, ...) snprintf(buffer, sizeof(buffer), __VA_ARGS__)
94 
95 #if defined(WIN32) || defined(__CYGWIN__)
96 #  define XINE_PATH_SEPARATOR_STRING ";"
97 #  define XINE_PATH_SEPARATOR_CHAR ';'
98 #  define XINE_DIRECTORY_SEPARATOR_STRING "\\"
99 #  define XINE_DIRECTORY_SEPARATOR_CHAR '\\'
100 #else
101 #  define XINE_PATH_SEPARATOR_STRING ":"
102 #  define XINE_PATH_SEPARATOR_CHAR ':'
103 #  define XINE_DIRECTORY_SEPARATOR_STRING "/"
104 #  define XINE_DIRECTORY_SEPARATOR_CHAR '/'
105 #endif
106 
107 /* replacement of min/max macros */
108 #ifndef HAVE_MAX_MACRO
109 #define	MAX(a,b) (((a)>(b))?(a):(b))
110 #endif
111 #ifndef HAVE_MIN_MACRO
112 #define	MIN(a,b) (((a)<(b))?(a):(b))
113 #endif
114 
115 #ifndef HAVE_STRLCAT
116 #define HAVE_STRLCAT
117 #define strlcat(D, S, N) xine_private_strlcat((D), (S), (N))
118 size_t xine_private_strlcat(char *dst, const char *src, size_t size);
119 #endif
120 
121 #ifndef HAVE_STRLCPY
122 #define HAVE_STRLCPY
123 #define strlcpy(D, S, N) xine_private_strlcpy((D), (S), (N))
124 size_t xine_private_strlcpy(char *dst, const char *src, size_t size);
125 #endif
126 
127 /* replacement of strndup */
128 #ifndef HAVE_STRNDUP
129 #define HAVE_STRNDUP
130 #define strndup(S, N) xine_private_strndup((S), (N))
131 char *xine_private_strndup(const char *s, size_t n);
132 #endif
133 
134 /* replacement of basename */
135 #ifndef HAVE_BASENAME
136 #define HAVE_BASENAME
137 #define basename(PATH) xine_private_basename((PATH))
138 char *xine_private_basename(char *path);
139 #endif
140 
141 /* replacement of hstrerror */
142 #ifndef HAVE_HSTRERROR
143 #define HAVE_HSTRERROR
144 #define hstrerror(ERR) xine_private_hstrerror((ERR))
145 const char *xine_private_hstrerror(int err);
146 #endif
147 
148 /* replacement of setenv */
149 #ifndef HAVE_SETENV
150 #define HAVE_SETENV
151 #define setenv(NAME, VALUE, OVERWRITE) xine_private_setenv((NAME), (VALUE))
152 int xine_private_setenv(const char *name, const char *value);
153 #endif
154 
155 /* replacement of strcasestr */
156 #ifndef HAVE_STRCASESTR
157 #define HAVE_STRCASESTR
158 #define strcasestr(HAYSTACK, NEEDLE) xine_private_strcasestr((HAYSTACK), (NEEDLE))
159 char *xine_private_strcasestr(const char *haystack, const char *needle);
160 #endif
161 
162 /* replacement of strtok_r */
163 #ifndef HAVE_STRTOK_R
164 #define HAVE_STRTOK_R
165 #define strtok_r(S, DELIM, PTRPTR) xine_private_strtok_r((S), (DELIM), (PTRPTR))
166 char *xine_private_strtok_r(char *s, const char *delim, char **ptrptr);
167 #endif
168 
169 #ifndef HAVE_SWAB
170 #define HAVE_SWAB
171 #define swab(A,B,C) xine_private_swab((A),(B),(C))
172 void xine_private_swab(const void *from, void *to, ssize_t n);
173 #endif
174 
175 /* replacement of gettimeofday */
176 #ifndef HAVE_GETTIMEOFDAY
177 #  define HAVE_GETTIMEOFDAY
178 #  ifdef WIN32
179 #    include <winsock.h>
180 struct timezone;
181 #  else
182 #    include <sys/time.h>
183 #  endif
184 #  define gettimeofday(TV, TZ) xine_private_gettimeofday((TV))
185 int xine_private_gettimeofday(struct timeval *tv);
186 #endif
187 
188 /* replacement of strpbrk */
189 #ifndef HAVE_STRPBRK
190 #define HAVE_STRPBRK
191 #define strpbrk(S, ACCEPT) xine_private_strpbrk((S), (ACCEPT))
192 char *xine_private_strpbrk(const char *s, const char *accept);
193 #endif
194 
195 /* replacement of strsep */
196 #ifndef HAVE_STRSEP
197 #define HAVE_STRSEP
198 #define strsep(STRINGP, DELIM) xine_private_strsep((STRINGP), (DELIM))
199 char *xine_private_strsep(char **stringp, const char *delim);
200 #endif
201 
202 /* replacement of timegm */
203 #ifndef HAVE_TIMEGM
204 #define HAVE_TIMEGM
205 #include <time.h>
206 #define timegm(TM) xine_private_timegm((TM))
207 time_t xine_private_timegm(struct tm *tm);
208 #endif
209 
210 /* replacement of unsetenv */
211 #ifndef HAVE_UNSETENV
212 #define HAVE_UNSETENV
213 #define unsetenv(NAME) xine_private_unsetenv((NAME))
214 void xine_private_unsetenv(const char *name);
215 #endif
216 
217 /* replacement of asprintf & vasprintf */
218 #ifndef HAVE_ASPRINTF
219 #define HAVE_ASPRINTF
220 #ifdef __GNUC__
221   #define asprintf(STRINGPP, FORMAT, ARGS...) xine_private_asprintf((STRINGPP), FORMAT, ##ARGS)
222 #elif defined (_MSC_VER)
223   #define asprintf(STRINGPP, FORMATARGS) xine_private_asprintf((STRINGPP), FORMATARGS)
224 #else
225   #define asprintf(STRINGPP, FORMAT, ...) xine_private_asprintf((STRINGPP), FORMAT, __VA_ARGS__)
226 #endif
227 #define vasprintf(STRINGPP, FORMAT, VA_ARG) xine_private_vasprintf((STRINGPP), (FORMAT), (VA_ARG))
228 int xine_private_asprintf(char **string, const char *format, ...) XINE_FORMAT_PRINTF(2, 3);
229 int xine_private_vasprintf(char **string, const char *format, va_list ap) XINE_FORMAT_PRINTF(2, 0);
230 #endif
231 
232 /* replacement of strndup */
233 #ifndef HAVE_STRNDUP
234 #define HAVE_STRNDUP
235 #define strndup(S, N) xine_private_strndup((S), (N))
236 char *xine_private_strndup(const char *s, size_t n);
237 #endif
238 
239 /* replacement of pthread_mutex_timedlock */
240 #ifndef HAVE_PTHREAD_MUTEX_TIMEDLOCK
241 #define HAVE_PTHREAD_MUTEX_TIMEDLOCK
242 #define pthread_mutex_timedlock(M, T) xine_private_pthread_mutex_timedlock((M), (T))
243 int xine_private_pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abs_timeout);
244 #endif
245 
246 /* handle non-standard function names */
247 #if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
248 #  define HAVE_SNPRINTF
249 #  define snprintf _snprintf
250 #endif
251 #if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
252 #  define HAVE_VSNPRINTF
253 #  define vsnprintf _vsnprintf
254 #endif
255 #if !defined(HAVE_STRCASECMP) && defined(HAVE__STRICMP)
256 #  define HAVE_STRCASECMP
257 #  define strcasecmp _stricmp
258 #endif
259 #if !defined(HAVE_STRNCASECMP) && defined(HAVE__STRNICMP)
260 #  define HAVE_STRNCASECMP
261 #  define strncasecmp _strnicmp
262 #endif
263 
264 #include <math.h>
265 #ifndef M_PI
266 #  define M_PI 3.14159265358979323846
267 #endif
268 
269 #ifdef WIN32
270 /* this hack applied only on attic version of MinGW platform */
271 #  if !defined(va_copy) && !defined(HAVE_VA_COPY)
272 #    define va_copy(DEST, SRC) ((DEST) = (SRC))
273 #  endif
274 
275 #  include <io.h>
276 #  ifdef _MSC_VER
277 #    include <direct.h>
278 #  endif
279 #  ifdef HAVE_SYS_STAT_H
280 #    include <sys/stat.h>
281 #  endif
282 #  ifdef __MINGW64__
283 #    define mkdir(A, B) mkdir((A))
284 #  else
285 #    define mkdir(A, B) _mkdir((A))
286 #  endif
287 
288 #  ifndef S_ISDIR
289 #    define S_ISDIR(m) ((m) & _S_IFDIR)
290 #  endif
291 
292 #  ifndef S_ISREG
293 #    define S_ISREG(m) ((m) & _S_IFREG)
294 #  endif
295 
296 #  ifndef S_ISBLK
297 #    define S_ISBLK(m) 0
298 #  endif
299 
300 #  ifndef S_ISCHR
301 #    define S_ISCHR(m) 0
302 #  endif
303 
304 #  ifndef S_ISLNK
305 #    define S_ISLNK(mode)  0
306 #  endif
307 
308 #  ifndef S_ISSOCK
309 #    define S_ISSOCK(mode) 0
310 #  endif
311 
312 #  ifndef S_ISFIFO
313 #    define S_ISFIFO(mode) 0
314 #  endif
315 
316 #  ifndef S_IXUSR
317 #    define S_IXUSR S_IEXEC
318 #  endif
319 
320 #  ifndef S_IXGRP
321 #    define S_IXGRP S_IEXEC
322 #  endif
323 
324 #  ifndef S_IXOTH
325 #    define S_IXOTH S_IEXEC
326 #  endif
327 
328 #  if !S_IXUGO
329 #    define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
330 #  endif
331 
332 /*
333  * workaround compatibility code due to 'near' and 'far' keywords in windef.h
334  * (do it only inside ffmpeg)
335  */
336 #  ifdef HAVE_AV_CONFIG_H
337 #    include <windows.h>
338 #    ifdef near
339 #      undef near
340 #    endif
341 #    ifdef far
342 #      undef far
343 #    endif
344 #    ifdef frm1
345 #      undef frm1
346 #    endif
347      /* it sucks everywhere :-) */
348 #    define near win32_sucks_near
349 #    define far win32_sucks_far
350 #  endif /* av_config */
351 
352 #endif
353 
354 #ifndef HAVE_READLINK
355 #  define readlink(PATH, BUF, BUFSIZE) 0
356 #endif
357 
358 /* replacing lstat by stat */
359 #ifndef HAVE_LSTAT
360 #  define HAVE_LSTAT
361 #  define lstat(FILENAME, BUF) stat((FILENAME), (BUF))
362 #endif
363 
364 /* replace llabs */
365 #ifndef HAVE_LLABS
366 #  define llabs(a) (((a) < 0) ? (-a) : (a))
367 #endif
368 
369 /* replacements of dirent for MSVC platform */
370 #ifndef HAVE_OPENDIR
371 #define HAVE_OPENDIR
372 typedef struct DIR DIR;
373 
374 struct dirent {
375   unsigned short d_reclen;
376   char *d_name;
377 };
378 
379 DIR           *xine_private_opendir(const char *);
380 int           xine_private_closedir(DIR *);
381 struct dirent *xine_private_readdir(DIR *);
382 void          xine_private_rewinddir(DIR *);
383 
384 #define opendir(DIRENT_NAME) xine_private_opendir((DIRENT_NAME))
385 #define closedir(DIRENT_DIR) xine_private_closedir((DIRENT_DIR))
386 #define readdir(DIRENT_DIR) xine_private_readdir((DIRENT_DIR))
387 #define rewinddir(DIRENT_DIR) xine_private_rewinddir((DIRENT_DIR))
388 
389 #endif
390 
391 /* replacement of memmem */
392 #ifndef HAVE_MEMMEM
393 #define HAVE_MEMMEM
394 #define memmem(H, HL, N, NL) \
395   xine_private_memmem((H), (HL), (N), (NL))
396 void *xine_private_memmem (const void *haystack, size_t haystack_len,
397 			   const void *needle, size_t needle_len);
398 #endif
399 
400 #endif
401