comparison include/SDL_string.h @ 1330:450721ad5436

It's now possible to build SDL without any C runtime at all on Windows, using Visual C++ 2005
author Sam Lantinga <slouken@libsdl.org>
date Mon, 06 Feb 2006 08:28:51 +0000
parents
children 3692456e7b0f
comparison
equal deleted inserted replaced
1329:bc67bbf87818 1330:450721ad5436
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
22
23 /* This file contains portable string manipulation functions for SDL */
24
25 #ifndef _SDL_string_h
26 #define _SDL_string_h
27
28 #include "SDL_config.h"
29
30 #ifdef HAVE_STDIO_H
31 #include <stdio.h> /* For snprintf() and friends */
32 #endif
33
34 #ifdef HAVE_STRING_H
35 #include <string.h>
36 #endif
37
38 #include "SDL_types.h"
39 #include "SDL_stdarg.h"
40
41 #include "begin_code.h"
42 /* Set up for C function definitions, even when using C++ */
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 #ifndef HAVE_MEMSET
48 #define memset SDL_memset
49 #endif
50 #ifndef SDL_memset
51 extern DECLSPEC void * SDLCALL SDL_memset(void *dst, int c, size_t len);
52 #endif
53
54 #if defined(__GNUC__) && defined(i386)
55 #define SDL_memset4(dst, val, len) \
56 do { \
57 int u0, u1, u2; \
58 __asm__ __volatile__ ( \
59 "cld\n\t" \
60 "rep ; stosl\n\t" \
61 : "=&D" (u0), "=&a" (u1), "=&c" (u2) \
62 : "0" (dst), "1" (val), "2" ((Uint32)(len)) \
63 : "memory" ); \
64 } while(0)
65 #endif
66 #ifndef SDL_memset4
67 #define SDL_memset4(dst, val, len) \
68 do { \
69 unsigned _count = (len); \
70 unsigned _n = (_count + 3) / 4; \
71 Uint32 *_p = (Uint32 *)(dst); \
72 Uint32 _val = (val); \
73 switch (_count % 4) { \
74 case 0: do { *_p++ = _val; \
75 case 3: *_p++ = _val; \
76 case 2: *_p++ = _val; \
77 case 1: *_p++ = _val; \
78 } while ( --_n ); \
79 } \
80 } while(0)
81 #endif
82
83 #if defined(__GNUC__) && defined(i386)
84 #define SDL_memcpy(dst, src, len) \
85 do { \
86 int u0, u1, u2; \
87 __asm__ __volatile__ ( \
88 "cld\n\t" \
89 "rep ; movsl\n\t" \
90 "testb $2,%b4\n\t" \
91 "je 1f\n\t" \
92 "movsw\n" \
93 "1:\ttestb $1,%b4\n\t" \
94 "je 2f\n\t" \
95 "movsb\n" \
96 "2:" \
97 : "=&c" (u0), "=&D" (u1), "=&S" (u2) \
98 : "0" ((unsigned)(len)/4), "q" (len), "1" (dst),"2" (src) \
99 : "memory" ); \
100 } while(0)
101 #define SDL_memcpy4(dst, src, len) \
102 do { \
103 int ecx, edi, esi; \
104 __asm__ __volatile__ ( \
105 "cld\n\t" \
106 "rep ; movsl" \
107 : "=&c" (ecx), "=&D" (edi), "=&S" (esi) \
108 : "0" ((unsigned)(len)), "1" (dst), "2" (src) \
109 : "memory" ); \
110 } while(0)
111 #endif
112 #ifndef HAVE_MEMCPY
113 #define memcpy SDL_memcpy
114 #endif
115 #ifndef SDL_memcpy
116 extern DECLSPEC void * SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
117 #endif
118
119 #if defined(__GNUC__) && defined(i386)
120 #define SDL_memcpy4(dst, src, len) \
121 do { \
122 int ecx, edi, esi; \
123 __asm__ __volatile__ ( \
124 "cld\n\t" \
125 "rep ; movsl" \
126 : "=&c" (ecx), "=&D" (edi), "=&S" (esi) \
127 : "0" ((unsigned)(len)), "1" (dst), "2" (src) \
128 : "memory" ); \
129 } while(0)
130 #endif
131 #ifndef SDL_memcpy4
132 #define SDL_memcpy4(dst, src, len) SDL_memcpy(dst, src, (len) << 2)
133 #endif
134
135 #if defined(__GNUC__) && defined(i386)
136 #define SDL_revcpy(dst, src, len) \
137 do { \
138 int u0, u1, u2; \
139 char *dstp = (char *)(dst); \
140 char *srcp = (char *)(src); \
141 int n = (len); \
142 if ( n >= 4 ) { \
143 __asm__ __volatile__ ( \
144 "std\n\t" \
145 "rep ; movsl\n\t" \
146 : "=&c" (u0), "=&D" (u1), "=&S" (u2) \
147 : "0" (n >> 2), \
148 "1" (dstp+(n-4)), "2" (srcp+(n-4)) \
149 : "memory" ); \
150 } \
151 switch (n & 3) { \
152 case 3: dstp[2] = srcp[2]; \
153 case 2: dstp[1] = srcp[1]; \
154 case 1: dstp[0] = srcp[0]; \
155 break; \
156 default: \
157 break; \
158 } \
159 } while(0)
160 #endif
161 #ifndef SDL_revcpy
162 extern DECLSPEC void * SDLCALL SDL_revcpy(void *dst, const void *src, size_t len);
163 #endif
164
165 #ifndef HAVE_MEMMOVE
166 #define memmove SDL_memmove
167 #endif
168 #define SDL_memmove(dst, src, len) \
169 do { \
170 if ( dst < src ) { \
171 SDL_memcpy(dst, src, len); \
172 } else { \
173 SDL_revcpy(dst, src, len); \
174 } \
175 } while(0)
176
177 #ifndef HAVE_MEMCMP
178 #define memcmp SDL_memcmp
179 #endif
180 #ifndef SDL_memcmp
181 extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
182 #endif
183
184 #ifdef HAVE_STRLEN
185 #define SDL_strlen strlen
186 #else
187 #define strlen SDL_strlen
188 extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string);
189 #endif
190
191 #ifdef HAVE_STRCPY
192 #define SDL_strcpy strcpy
193 #else
194 #define strcpy SDL_strcpy
195 extern DECLSPEC char * SDLCALL SDL_strcpy(char *dst, const char *src);
196 #endif
197
198 #ifdef HAVE_STRNCPY
199 #define SDL_strncpy strncpy
200 #else
201 #define strncpy SDL_strncpy
202 extern DECLSPEC char * SDLCALL SDL_strncpy(char *dst, const char *src, size_t maxlen);
203 #endif
204
205 #ifdef HAVE__STRREV
206 #define SDL_strrev _strrev
207 #else
208 #define _strrev SDL_strrev
209 extern DECLSPEC char * SDLCALL SDL_strrev(char *string);
210 #endif
211
212 #ifdef HAVE__STRUPR
213 #define SDL_strupr _strupr
214 #else
215 #define _strupr SDL_strupr
216 extern DECLSPEC char * SDLCALL SDL_strupr(char *string);
217 #endif
218
219 #ifdef HAVE__STRLWR
220 #define SDL_strlwr _strlwr
221 #else
222 #define _strlwr SDL_strlwr
223 extern DECLSPEC char * SDLCALL SDL_strlwr(char *string);
224 #endif
225
226 #ifdef HAVE_STRCHR
227 #define SDL_strchr strchr
228 #else
229 #define strchr SDL_strchr
230 extern DECLSPEC char * SDLCALL SDL_strchr(const char *string, int c);
231 #endif
232
233 #ifdef HAVE_STRRCHR
234 #define SDL_strrchr strrchr
235 #else
236 #define strrchr SDL_strrchr
237 extern DECLSPEC char * SDLCALL SDL_strrchr(const char *string, int c);
238 #endif
239
240 #ifdef HAVE_STRSTR
241 #define SDL_strstr strstr
242 #else
243 #define strstr SDL_strstr
244 extern DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
245 #endif
246
247 #ifdef HAVE_ITOA
248 #define SDL_itoa itoa
249 #else
250 #define itoa SDL_itoa
251 #define SDL_itoa(value, string, radix) SDL_ltoa((long)value, string, radix)
252 #endif
253
254 #ifdef HAVE__LTOA
255 #define SDL_ltoa _ltoa
256 #else
257 #define _ltoa SDL_ltoa
258 extern DECLSPEC char * SDLCALL SDL_ltoa(long value, char *string, int radix);
259 #endif
260
261 #ifdef HAVE__UITOA
262 #define SDL_uitoa _uitoa
263 #else
264 #define _uitoa SDL_uitoa
265 #define SDL_uitoa(value, string, radix) SDL_ultoa((long)value, string, radix)
266 #endif
267
268 #ifdef HAVE__ULTOA
269 #define SDL_ultoa _ultoa
270 #else
271 #define _ultoa SDL_ultoa
272 extern DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *string, int radix);
273 #endif
274
275 #ifdef HAVE_STRTOL
276 #define SDL_strtol strtol
277 #else
278 #define strtol SDL_strtol
279 extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp, int base);
280 #endif
281
282 #ifdef SDL_HAS_64BIT_TYPE
283
284 #ifdef HAVE__I64TOA
285 #define SDL_lltoa _i64toa
286 #else
287 #define _i64toa SDL_lltoa
288 extern DECLSPEC char* SDLCALL SDL_lltoa(Sint64 value, char *string, int radix);
289 #endif
290
291 #ifdef HAVE__UI64TOA
292 #define SDL_ulltoa _ui64toa
293 #else
294 #define _ui64toa SDL_ulltoa
295 extern DECLSPEC char* SDLCALL SDL_ulltoa(Uint64 value, char *string, int radix);
296 #endif
297
298 #ifdef HAVE_STRTOLL
299 #define SDL_strtoll strtoll
300 #else
301 #define strtoll SDL_strtoll
302 extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp, int base);
303 #endif
304
305 #endif /* SDL_HAS_64BIT_TYPE */
306
307 #ifdef HAVE_STRCMP
308 #define SDL_strcmp strcmp
309 #else
310 #define strcmp SDL_strcmp
311 extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
312 #endif
313
314 #ifdef HAVE_STRNCMP
315 #define SDL_strncmp strncmp
316 #else
317 #define strncmp SDL_strncmp
318 extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
319 #endif
320
321 #if defined(HAVE_STRICMP) && !defined(HAVE_STRCASECMP)
322 #define strcasecmp stricmp
323 #define HAVE_STRCASECMP
324 #endif
325 #ifdef HAVE_STRCASECMP
326 #define SDL_strcasecmp strcasecmp
327 #else
328 #define strcasecmp SDL_strcasecmp
329 extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
330 #endif
331
332 #ifdef HAVE_SSCANF
333 #define SDL_sscanf sscanf
334 #else
335 #define sscanf SDL_sscanf
336 extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
337 #endif
338
339 #ifdef HAVE_SNPRINTF
340 #define SDL_snprintf snprintf
341 #else
342 #define snprintf SDL_snprintf
343 extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
344 #endif
345
346 #ifdef HAVE_VSNPRINTF
347 #define SDL_vsnprintf vsnprintf
348 #else
349 #define vsnprintf SDL_vsnprintf
350 extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
351 #endif
352
353 /* Ends C function definitions when using C++ */
354 #ifdef __cplusplus
355 }
356 #endif
357 #include "close_code.h"
358
359 #endif /* _SDL_string_h */