Subversion Repositories Kolibri OS

Rev

Rev 1905 | Details | Compare with Previous | 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"
3960 Serge 18
#include "intsym.h"
1905 serge 19
 
20
#ifdef HAVE_STDLIB_H
21
/* realloc, size_t */
22
#include 
23
#endif
24
 
25
#include        
26
#include        
27
 
28
#ifdef HAVE_SIGNAL_H
29
#include 
30
#else
31
#ifdef HAVE_SYS_SIGNAL_H
32
#include 
33
#endif
34
#endif
35
 
36
#ifdef HAVE_UNISTD_H
37
#include 
38
#endif
39
 
40
/* Types, types, types. */
41
/* Do we actually need these two in addition to sys/types.h? As replacement? */
42
#ifdef HAVE_SYS_TYPES_H
43
#include 
44
#endif
45
#ifdef HAVE_INTTYPES_H
46
#include 
47
#endif
48
#ifdef HAVE_STDINT_H
49
#include 
50
#endif
51
/* We want SIZE_MAX, etc. */
52
#ifdef HAVE_LIMITS_H
53
#include 
54
#endif
55
 
56
#ifndef SIZE_MAX
57
#define SIZE_MAX ((size_t)-1)
58
#endif
59
#ifndef ULONG_MAX
60
#define ULONG_MAX ((unsigned long)-1)
61
#endif
62
 
63
#ifdef HAVE_STRING_H
64
#include 
65
#endif
66
 
67
#ifdef OS2
68
#include 
69
#endif
70
 
71
#ifdef HAVE_SYS_TIME_H
72
#include 
73
#endif
74
/* For select(), I need select.h according to POSIX 2001, else: sys/time.h sys/types.h unistd.h */
75
#ifdef HAVE_SYS_SELECT_H
76
#include 
77
#endif
78
 
79
/* To parse big numbers... */
80
#ifdef HAVE_ATOLL
81
#define atobigint atoll
82
#else
83
#define atobigint atol
84
#endif
85
 
86
typedef unsigned char byte;
87
 
88
/* A safe realloc also for very old systems where realloc(NULL, size) returns NULL. */
89
void *safe_realloc(void *ptr, size_t size);
90
#ifndef HAVE_STRERROR
91
const char *strerror(int errnum);
92
#endif
93
 
94
#ifndef HAVE_STRDUP
95
char *strdup(const char *s);
96
#endif
97
 
98
/* If we have the size checks enabled, try to derive some sane printfs.
99
   Simple start: Use max integer type and format if long is not big enough.
100
   I am hesitating to use %ll without making sure that it's there... */
101
#if !(defined PLAIN_C89) && (defined SIZEOF_OFF_T) && (SIZEOF_OFF_T > SIZEOF_LONG) && (defined PRIiMAX)
102
# define OFF_P PRIiMAX
103
typedef intmax_t off_p;
104
#else
105
# define OFF_P "li"
106
typedef long off_p;
107
#endif
108
 
109
#if !(defined PLAIN_C89) && (defined SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > SIZEOF_LONG) && (defined PRIuMAX)
110
# define SIZE_P PRIuMAX
111
typedef uintmax_t size_p;
112
#else
113
# define SIZE_P "lu"
114
typedef unsigned long size_p;
115
#endif
116
 
117
#if !(defined PLAIN_C89) && (defined SIZEOF_SSIZE_T) && (SIZEOF_SSIZE_T > SIZEOF_LONG) && (defined PRIiMAX)
118
# define SSIZE_P PRIuMAX
119
typedef intmax_t ssize_p;
120
#else
121
# define SSIZE_P "li"
122
typedef long ssize_p;
123
#endif
124
 
3960 Serge 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);
1905 serge 171
#endif
3960 Serge 172
 
173
/* That one comes from Tellie on OS/2, needed in resolver. */
174
#ifdef __KLIBC__
175
typedef int socklen_t;
176
#endif
177
 
178
#endif