Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1905 | serge | 1 | /* |
2 | compat: Some compatibility functions and header inclusions. |
||
3 | Basic standard C stuff, that may barely be above/around C89. |
||
4 | |||
5 | The mpg123 code is determined to keep it's legacy. A legacy of old, old UNIX. |
||
6 | It is envisioned to include this compat header instead of any of the "standard" headers, to catch compatibility issues. |
||
7 | So, don't include stdlib.h or string.h ... include compat.h. |
||
8 | |||
9 | copyright 2007-8 by the mpg123 project - free software under the terms of the LGPL 2.1 |
||
10 | see COPYING and AUTHORS files in distribution or http://mpg123.org |
||
11 | initially written by Thomas Orgis |
||
12 | */ |
||
13 | |||
14 | #ifndef MPG123_COMPAT_H |
||
15 | #define MPG123_COMPAT_H |
||
16 | |||
17 | #include "config.h" |
||
18 | |||
19 | #ifdef HAVE_STDLIB_H |
||
20 | /* realloc, size_t */ |
||
21 | #include |
||
22 | #endif |
||
23 | |||
24 | #include |
||
25 | #include |
||
26 | |||
27 | #ifdef HAVE_SIGNAL_H |
||
28 | #include |
||
29 | #else |
||
30 | #ifdef HAVE_SYS_SIGNAL_H |
||
31 | #include |
||
32 | #endif |
||
33 | #endif |
||
34 | |||
35 | #ifdef HAVE_UNISTD_H |
||
36 | #include |
||
37 | #endif |
||
38 | |||
39 | /* Types, types, types. */ |
||
40 | /* Do we actually need these two in addition to sys/types.h? As replacement? */ |
||
41 | #ifdef HAVE_SYS_TYPES_H |
||
42 | #include |
||
43 | #endif |
||
44 | #ifdef HAVE_INTTYPES_H |
||
45 | #include |
||
46 | #endif |
||
47 | #ifdef HAVE_STDINT_H |
||
48 | #include |
||
49 | #endif |
||
50 | /* We want SIZE_MAX, etc. */ |
||
51 | #ifdef HAVE_LIMITS_H |
||
52 | #include |
||
53 | #endif |
||
54 | |||
55 | #ifndef SIZE_MAX |
||
56 | #define SIZE_MAX ((size_t)-1) |
||
57 | #endif |
||
58 | #ifndef ULONG_MAX |
||
59 | #define ULONG_MAX ((unsigned long)-1) |
||
60 | #endif |
||
61 | |||
62 | #ifdef HAVE_STRING_H |
||
63 | #include |
||
64 | #endif |
||
65 | |||
66 | #ifdef OS2 |
||
67 | #include |
||
68 | #endif |
||
69 | |||
70 | #ifdef HAVE_SYS_TIME_H |
||
71 | #include |
||
72 | #endif |
||
73 | /* For select(), I need select.h according to POSIX 2001, else: sys/time.h sys/types.h unistd.h */ |
||
74 | #ifdef HAVE_SYS_SELECT_H |
||
75 | #include |
||
76 | #endif |
||
77 | |||
78 | /* To parse big numbers... */ |
||
79 | #ifdef HAVE_ATOLL |
||
80 | #define atobigint atoll |
||
81 | #else |
||
82 | #define atobigint atol |
||
83 | #endif |
||
84 | |||
85 | typedef unsigned char byte; |
||
86 | |||
87 | /* A safe realloc also for very old systems where realloc(NULL, size) returns NULL. */ |
||
88 | void *safe_realloc(void *ptr, size_t size); |
||
89 | #ifndef HAVE_STRERROR |
||
90 | const char *strerror(int errnum); |
||
91 | #endif |
||
92 | |||
93 | #ifndef HAVE_STRDUP |
||
94 | char *strdup(const char *s); |
||
95 | #endif |
||
96 | |||
97 | /* If we have the size checks enabled, try to derive some sane printfs. |
||
98 | Simple start: Use max integer type and format if long is not big enough. |
||
99 | I am hesitating to use %ll without making sure that it's there... */ |
||
100 | #if !(defined PLAIN_C89) && (defined SIZEOF_OFF_T) && (SIZEOF_OFF_T > SIZEOF_LONG) && (defined PRIiMAX) |
||
101 | # define OFF_P PRIiMAX |
||
102 | typedef intmax_t off_p; |
||
103 | #else |
||
104 | # define OFF_P "li" |
||
105 | typedef long off_p; |
||
106 | #endif |
||
107 | |||
108 | #if !(defined PLAIN_C89) && (defined SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > SIZEOF_LONG) && (defined PRIuMAX) |
||
109 | # define SIZE_P PRIuMAX |
||
110 | typedef uintmax_t size_p; |
||
111 | #else |
||
112 | # define SIZE_P "lu" |
||
113 | typedef unsigned long size_p; |
||
114 | #endif |
||
115 | |||
116 | #if !(defined PLAIN_C89) && (defined SIZEOF_SSIZE_T) && (SIZEOF_SSIZE_T > SIZEOF_LONG) && (defined PRIiMAX) |
||
117 | # define SSIZE_P PRIuMAX |
||
118 | typedef intmax_t ssize_p; |
||
119 | #else |
||
120 | # define SSIZE_P "li" |
||
121 | typedef long ssize_p; |
||
122 | #endif |
||
123 | |||
124 | #endif |