Subversion Repositories Kolibri OS

Rev

Rev 1905 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1905 Rev 3960
1
/*
1
/*
2
	compat: Some compatibility functions and header inclusions.
2
	compat: Some compatibility functions and header inclusions.
3
	Basic standard C stuff, that may barely be above/around C89.
3
	Basic standard C stuff, that may barely be above/around C89.
4
 
4
 
5
	The mpg123 code is determined to keep it's legacy. A legacy of old, old UNIX.
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.
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.
7
	So, don't include stdlib.h or string.h ... include compat.h.
8
 
8
 
9
	copyright 2007-8 by the mpg123 project - free software under the terms of the LGPL 2.1
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
10
	see COPYING and AUTHORS files in distribution or http://mpg123.org
11
	initially written by Thomas Orgis
11
	initially written by Thomas Orgis
12
*/
12
*/
13
 
13
 
14
#ifndef MPG123_COMPAT_H
14
#ifndef MPG123_COMPAT_H
15
#define MPG123_COMPAT_H
15
#define MPG123_COMPAT_H
16
 
16
 
17
#include "config.h"
17
#include "config.h"
-
 
18
#include "intsym.h"
18
 
19
 
19
#ifdef HAVE_STDLIB_H
20
#ifdef HAVE_STDLIB_H
20
/* realloc, size_t */
21
/* realloc, size_t */
21
#include 
22
#include 
22
#endif
23
#endif
23
 
24
 
24
#include        
25
#include        
25
#include        
26
#include        
26
 
27
 
27
#ifdef HAVE_SIGNAL_H
28
#ifdef HAVE_SIGNAL_H
28
#include 
29
#include 
29
#else
30
#else
30
#ifdef HAVE_SYS_SIGNAL_H
31
#ifdef HAVE_SYS_SIGNAL_H
31
#include 
32
#include 
32
#endif
33
#endif
33
#endif
34
#endif
34
 
35
 
35
#ifdef HAVE_UNISTD_H
36
#ifdef HAVE_UNISTD_H
36
#include 
37
#include 
37
#endif
38
#endif
38
 
39
 
39
/* Types, types, types. */
40
/* Types, types, types. */
40
/* Do we actually need these two in addition to sys/types.h? As replacement? */
41
/* Do we actually need these two in addition to sys/types.h? As replacement? */
41
#ifdef HAVE_SYS_TYPES_H
42
#ifdef HAVE_SYS_TYPES_H
42
#include 
43
#include 
43
#endif
44
#endif
44
#ifdef HAVE_INTTYPES_H
45
#ifdef HAVE_INTTYPES_H
45
#include 
46
#include 
46
#endif
47
#endif
47
#ifdef HAVE_STDINT_H
48
#ifdef HAVE_STDINT_H
48
#include 
49
#include 
49
#endif
50
#endif
50
/* We want SIZE_MAX, etc. */
51
/* We want SIZE_MAX, etc. */
51
#ifdef HAVE_LIMITS_H
52
#ifdef HAVE_LIMITS_H
52
#include 
53
#include 
53
#endif
54
#endif
54
 
55
 
55
#ifndef SIZE_MAX
56
#ifndef SIZE_MAX
56
#define SIZE_MAX ((size_t)-1)
57
#define SIZE_MAX ((size_t)-1)
57
#endif
58
#endif
58
#ifndef ULONG_MAX
59
#ifndef ULONG_MAX
59
#define ULONG_MAX ((unsigned long)-1)
60
#define ULONG_MAX ((unsigned long)-1)
60
#endif
61
#endif
61
 
62
 
62
#ifdef HAVE_STRING_H
63
#ifdef HAVE_STRING_H
63
#include 
64
#include 
64
#endif
65
#endif
65
 
66
 
66
#ifdef OS2
67
#ifdef OS2
67
#include 
68
#include 
68
#endif
69
#endif
69
 
70
 
70
#ifdef HAVE_SYS_TIME_H
71
#ifdef HAVE_SYS_TIME_H
71
#include 
72
#include 
72
#endif
73
#endif
73
/* For select(), I need select.h according to POSIX 2001, else: sys/time.h sys/types.h unistd.h */
74
/* 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
#ifdef HAVE_SYS_SELECT_H
75
#include 
76
#include 
76
#endif
77
#endif
77
 
78
 
78
/* To parse big numbers... */
79
/* To parse big numbers... */
79
#ifdef HAVE_ATOLL
80
#ifdef HAVE_ATOLL
80
#define atobigint atoll
81
#define atobigint atoll
81
#else
82
#else
82
#define atobigint atol
83
#define atobigint atol
83
#endif
84
#endif
84
 
85
 
85
typedef unsigned char byte;
86
typedef unsigned char byte;
86
 
87
 
87
/* A safe realloc also for very old systems where realloc(NULL, size) returns NULL. */
88
/* A safe realloc also for very old systems where realloc(NULL, size) returns NULL. */
88
void *safe_realloc(void *ptr, size_t size);
89
void *safe_realloc(void *ptr, size_t size);
89
#ifndef HAVE_STRERROR
90
#ifndef HAVE_STRERROR
90
const char *strerror(int errnum);
91
const char *strerror(int errnum);
91
#endif
92
#endif
92
 
93
 
93
#ifndef HAVE_STRDUP
94
#ifndef HAVE_STRDUP
94
char *strdup(const char *s);
95
char *strdup(const char *s);
95
#endif
96
#endif
96
 
97
 
97
/* If we have the size checks enabled, try to derive some sane printfs.
98
/* 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
   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
   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
#if !(defined PLAIN_C89) && (defined SIZEOF_OFF_T) && (SIZEOF_OFF_T > SIZEOF_LONG) && (defined PRIiMAX)
101
# define OFF_P PRIiMAX
102
# define OFF_P PRIiMAX
102
typedef intmax_t off_p;
103
typedef intmax_t off_p;
103
#else
104
#else
104
# define OFF_P "li"
105
# define OFF_P "li"
105
typedef long off_p;
106
typedef long off_p;
106
#endif
107
#endif
107
 
108
 
108
#if !(defined PLAIN_C89) && (defined SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > SIZEOF_LONG) && (defined PRIuMAX)
109
#if !(defined PLAIN_C89) && (defined SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > SIZEOF_LONG) && (defined PRIuMAX)
109
# define SIZE_P PRIuMAX
110
# define SIZE_P PRIuMAX
110
typedef uintmax_t size_p;
111
typedef uintmax_t size_p;
111
#else
112
#else
112
# define SIZE_P "lu"
113
# define SIZE_P "lu"
113
typedef unsigned long size_p;
114
typedef unsigned long size_p;
114
#endif
115
#endif
115
 
116
 
116
#if !(defined PLAIN_C89) && (defined SIZEOF_SSIZE_T) && (SIZEOF_SSIZE_T > SIZEOF_LONG) && (defined PRIiMAX)
117
#if !(defined PLAIN_C89) && (defined SIZEOF_SSIZE_T) && (SIZEOF_SSIZE_T > SIZEOF_LONG) && (defined PRIiMAX)
117
# define SSIZE_P PRIuMAX
118
# define SSIZE_P PRIuMAX
118
typedef intmax_t ssize_p;
119
typedef intmax_t ssize_p;
119
#else
120
#else
120
# define SSIZE_P "li"
121
# define SSIZE_P "li"
121
typedef long ssize_p;
122
typedef long ssize_p;
122
#endif
123
#endif
-
 
124
 
-
 
125
/**
-
 
126
 * Opening a file handle can be different.
-
 
127
 * This function here is defined to take a path in native encoding (ISO8859 / UTF-8 / ...), or, when MS Windows Unicode support is enabled, an UTF-8 string that will be converted back to native UCS-2 (wide character) before calling the system's open function.
-
 
128
 * @param[in] wptr Pointer to wide string.
-
 
129
 * @param[in] mbptr Pointer to multibyte string.
-
 
130
 * @return file descriptor (>=0) or error code.
-
 
131
 */
-
 
132
int compat_open(const char *filename, int flags);
-
 
133
 
-
 
134
/**
-
 
135
 * Closing a file handle can be platform specific.
-
 
136
 * This function takes a file descriptor that is to be closed.
-
 
137
 * @param[in] infd File descriptor to be closed.
-
 
138
 * @return 0 if the file was successfully closed. A return value of -1 indicates an error.
-
 
139
 */
-
 
140
int compat_close(int infd);
-
 
141
 
-
 
142
/* Those do make sense in a separate file, but I chose to include them in compat.c because that's the one source whose object is shared between mpg123 and libmpg123 -- and both need the functionality internally. */
-
 
143
 
-
 
144
#ifdef WANT_WIN32_UNICODE
-
 
145
/**
-
 
146
 * win32_uni2mbc
-
 
147
 * Converts a null terminated UCS-2 string to a multibyte (UTF-8) equivalent.
-
 
148
 * Caller is supposed to free allocated buffer.
-
 
149
 * @param[in] wptr Pointer to wide string.
-
 
150
 * @param[out] mbptr Pointer to multibyte string.
-
 
151
 * @param[out] buflen Optional parameter for length of allocated buffer.
-
 
152
 * @return status of WideCharToMultiByte conversion.
-
 
153
 *
-
 
154
 * WideCharToMultiByte - http://msdn.microsoft.com/en-us/library/dd374130(VS.85).aspx
-
 
155
 */
-
 
156
int win32_wide_utf8(const wchar_t * const wptr, char **mbptr, size_t * buflen);
-
 
157
 
-
 
158
/**
-
 
159
 * win32_mbc2uni
-
 
160
 * Converts a null terminated UTF-8 string to a UCS-2 equivalent.
-
 
161
 * Caller is supposed to free allocated buffer.
-
 
162
 * @param[out] mbptr Pointer to multibyte string.
-
 
163
 * @param[in] wptr Pointer to wide string.
-
 
164
 * @param[out] buflen Optional parameter for length of allocated buffer.
-
 
165
 * @return status of WideCharToMultiByte conversion.
-
 
166
 *
-
 
167
 * MultiByteToWideChar - http://msdn.microsoft.com/en-us/library/dd319072(VS.85).aspx
-
 
168
 */
-
 
169
 
-
 
170
int win32_utf8_wide(const char *const mbptr, wchar_t **wptr, size_t *buflen);
-
 
171
#endif
-
 
172
 
-
 
173
/* That one comes from Tellie on OS/2, needed in resolver. */
-
 
174
#ifdef __KLIBC__
-
 
175
typedef int socklen_t;
-
 
176
#endif
123
 
177
 
124
#endif
178
#endif