Mercurial > sdl-ios-xcode
comparison src/SDL_error.c @ 1336:3692456e7b0f
Use SDL_ prefixed versions of C library functions.
FIXME:
Change #include <stdlib.h> to #include "SDL_stdlib.h"
Change #include <string.h> to #include "SDL_string.h"
Make sure nothing else broke because of this...
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 07 Feb 2006 06:59:48 +0000 |
parents | 450721ad5436 |
children | 604d73db6802 |
comparison
equal
deleted
inserted
replaced
1335:c39265384763 | 1336:3692456e7b0f |
---|---|
61 SDL_error *error; | 61 SDL_error *error; |
62 | 62 |
63 /* Copy in the key, mark error as valid */ | 63 /* Copy in the key, mark error as valid */ |
64 error = SDL_GetErrBuf(); | 64 error = SDL_GetErrBuf(); |
65 error->error = 1; | 65 error->error = 1; |
66 strncpy((char *)error->key, fmt, sizeof(error->key)); | 66 SDL_strncpy((char *)error->key, fmt, sizeof(error->key)); |
67 error->key[sizeof(error->key)-1] = '\0'; | 67 error->key[sizeof(error->key)-1] = '\0'; |
68 | 68 |
69 va_start(ap, fmt); | 69 va_start(ap, fmt); |
70 error->argc = 0; | 70 error->argc = 0; |
71 while ( *fmt ) { | 71 while ( *fmt ) { |
96 { | 96 { |
97 int index = error->argc; | 97 int index = error->argc; |
98 char *str = va_arg(ap, char *); | 98 char *str = va_arg(ap, char *); |
99 if (str == NULL) | 99 if (str == NULL) |
100 str = "(null)"; | 100 str = "(null)"; |
101 strncpy((char *)error->args[index].buf, str, ERR_MAX_STRLEN); | 101 SDL_strncpy((char *)error->args[index].buf, str, ERR_MAX_STRLEN); |
102 error->args[index].buf[ERR_MAX_STRLEN-1] = 0; | 102 error->args[index].buf[ERR_MAX_STRLEN-1] = 0; |
103 error->argc++; | 103 error->argc++; |
104 } | 104 } |
105 break; | 105 break; |
106 default: | 106 default: |
123 static int PrintInt(Uint16 *str, unsigned int maxlen, int value) | 123 static int PrintInt(Uint16 *str, unsigned int maxlen, int value) |
124 { | 124 { |
125 char tmp[128]; | 125 char tmp[128]; |
126 int len, i; | 126 int len, i; |
127 | 127 |
128 snprintf(tmp, SDL_arraysize(tmp), "%d", value); | 128 SDL_snprintf(tmp, SDL_arraysize(tmp), "%d", value); |
129 len = 0; | 129 len = 0; |
130 if ( strlen(tmp) < maxlen ) { | 130 if ( SDL_strlen(tmp) < maxlen ) { |
131 for ( i=0; tmp[i]; ++i ) { | 131 for ( i=0; tmp[i]; ++i ) { |
132 *str++ = tmp[i]; | 132 *str++ = tmp[i]; |
133 ++len; | 133 ++len; |
134 } | 134 } |
135 } | 135 } |
139 static int PrintDouble(Uint16 *str, unsigned int maxlen, double value) | 139 static int PrintDouble(Uint16 *str, unsigned int maxlen, double value) |
140 { | 140 { |
141 char tmp[128]; | 141 char tmp[128]; |
142 int len, i; | 142 int len, i; |
143 | 143 |
144 snprintf(tmp, SDL_arraysize(tmp), "%f", value); | 144 SDL_snprintf(tmp, SDL_arraysize(tmp), "%f", value); |
145 len = 0; | 145 len = 0; |
146 if ( strlen(tmp) < maxlen ) { | 146 if ( SDL_strlen(tmp) < maxlen ) { |
147 for ( i=0; tmp[i]; ++i ) { | 147 for ( i=0; tmp[i]; ++i ) { |
148 *str++ = tmp[i]; | 148 *str++ = tmp[i]; |
149 ++len; | 149 ++len; |
150 } | 150 } |
151 } | 151 } |
155 static int PrintPointer(Uint16 *str, unsigned int maxlen, void *value) | 155 static int PrintPointer(Uint16 *str, unsigned int maxlen, void *value) |
156 { | 156 { |
157 char tmp[128]; | 157 char tmp[128]; |
158 int len, i; | 158 int len, i; |
159 | 159 |
160 snprintf(tmp, SDL_arraysize(tmp), "%p", value); | 160 SDL_snprintf(tmp, SDL_arraysize(tmp), "%p", value); |
161 len = 0; | 161 len = 0; |
162 if ( strlen(tmp) < maxlen ) { | 162 if ( SDL_strlen(tmp) < maxlen ) { |
163 for ( i=0; tmp[i]; ++i ) { | 163 for ( i=0; tmp[i]; ++i ) { |
164 *str++ = tmp[i]; | 164 *str++ = tmp[i]; |
165 ++len; | 165 ++len; |
166 } | 166 } |
167 } | 167 } |
251 { | 251 { |
252 Uint16 *errstr16; | 252 Uint16 *errstr16; |
253 unsigned int i; | 253 unsigned int i; |
254 | 254 |
255 /* Allocate the UNICODE buffer */ | 255 /* Allocate the UNICODE buffer */ |
256 errstr16 = (Uint16 *)malloc(maxlen * (sizeof *errstr16)); | 256 errstr16 = (Uint16 *)SDL_malloc(maxlen * (sizeof *errstr16)); |
257 if ( ! errstr16 ) { | 257 if ( ! errstr16 ) { |
258 strncpy((char *)errstr, "Out of memory", maxlen); | 258 SDL_strncpy((char *)errstr, "Out of memory", maxlen); |
259 errstr[maxlen-1] = '\0'; | 259 errstr[maxlen-1] = '\0'; |
260 return(errstr); | 260 return(errstr); |
261 } | 261 } |
262 | 262 |
263 /* Get the error message */ | 263 /* Get the error message */ |
267 for ( i=0; i<maxlen; ++i ) { | 267 for ( i=0; i<maxlen; ++i ) { |
268 errstr[i] = (Uint8)errstr16[i]; | 268 errstr[i] = (Uint8)errstr16[i]; |
269 } | 269 } |
270 | 270 |
271 /* Free UNICODE buffer (if necessary) */ | 271 /* Free UNICODE buffer (if necessary) */ |
272 free(errstr16); | 272 SDL_free(errstr16); |
273 | 273 |
274 return(errstr); | 274 return(errstr); |
275 } | 275 } |
276 | 276 |
277 /* Available for backwards compatibility */ | 277 /* Available for backwards compatibility */ |
318 char buffer[BUFSIZ+1]; | 318 char buffer[BUFSIZ+1]; |
319 | 319 |
320 SDL_SetError("Hi there!"); | 320 SDL_SetError("Hi there!"); |
321 printf("Error 1: %s\n", SDL_GetError()); | 321 printf("Error 1: %s\n", SDL_GetError()); |
322 SDL_ClearError(); | 322 SDL_ClearError(); |
323 memset(buffer, '1', BUFSIZ); | 323 SDL_memset(buffer, '1', BUFSIZ); |
324 buffer[BUFSIZ] = 0; | 324 buffer[BUFSIZ] = 0; |
325 SDL_SetError("This is the error: %s (%f)", buffer, 1.0); | 325 SDL_SetError("This is the error: %s (%f)", buffer, 1.0); |
326 printf("Error 2: %s\n", SDL_GetError()); | 326 printf("Error 2: %s\n", SDL_GetError()); |
327 exit(0); | 327 exit(0); |
328 } | 328 } |