Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11video.c @ 1338:604d73db6802
Removed uses of stdlib.h and string.h
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 07 Feb 2006 09:29:18 +0000 |
parents | 3692456e7b0f |
children | c71e05b4dc2e |
comparison
equal
deleted
inserted
replaced
1337:c687f06c7473 | 1338:604d73db6802 |
---|---|
25 since the event thread uses a separate X connection and any | 25 since the event thread uses a separate X connection and any |
26 additional locking necessary is handled internally. However, | 26 additional locking necessary is handled internally. However, |
27 if full locking is neccessary, take a look at XInitThreads(). | 27 if full locking is neccessary, take a look at XInitThreads(). |
28 */ | 28 */ |
29 | 29 |
30 #include <stdlib.h> | |
31 #include <stdio.h> | |
32 #include <unistd.h> | 30 #include <unistd.h> |
33 #include <string.h> | |
34 #include <sys/ioctl.h> | 31 #include <sys/ioctl.h> |
35 #ifdef MTRR_SUPPORT | 32 #ifdef MTRR_SUPPORT |
36 #include <asm/mtrr.h> | 33 #include <asm/mtrr.h> |
37 #include <sys/fcntl.h> | 34 #include <sys/fcntl.h> |
38 #endif | 35 #endif |
39 | 36 |
40 #ifdef HAVE_ALLOCA_H | |
41 #include <alloca.h> | |
42 #endif | |
43 | |
44 #ifdef HAVE_ALLOCA | |
45 #define ALLOCA(n) ((void*)alloca(n)) | |
46 #define FREEA(p) | |
47 #else | |
48 #define ALLOCA(n) SDL_malloc(n) | |
49 #define FREEA(p) SDL_free(p) | |
50 #endif | |
51 | |
52 #include "SDL.h" | 37 #include "SDL.h" |
38 #include "SDL_stdlib.h" | |
39 #include "SDL_string.h" | |
53 #include "SDL_error.h" | 40 #include "SDL_error.h" |
54 #include "SDL_timer.h" | 41 #include "SDL_timer.h" |
55 #include "SDL_thread.h" | 42 #include "SDL_thread.h" |
56 #include "SDL_video.h" | 43 #include "SDL_video.h" |
57 #include "SDL_mouse.h" | 44 #include "SDL_mouse.h" |
297 } | 284 } |
298 | 285 |
299 /* Next look at the application's executable name */ | 286 /* Next look at the application's executable name */ |
300 #if defined(linux) || defined(__FreeBSD__) | 287 #if defined(linux) || defined(__FreeBSD__) |
301 #if defined(linux) | 288 #if defined(linux) |
302 sprintf(procfile, "/proc/%d/exe", getpid()); | 289 SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid()); |
303 #elif defined(__FreeBSD__) | 290 #elif defined(__FreeBSD__) |
304 sprintf(procfile, "/proc/%d/file", getpid()); | 291 SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file", getpid()); |
305 #else | 292 #else |
306 #error Where can we find the executable name? | 293 #error Where can we find the executable name? |
307 #endif | 294 #endif |
308 linksize = readlink(procfile, linkfile, sizeof(linkfile)-1); | 295 linksize = readlink(procfile, linkfile, sizeof(linkfile)-1); |
309 if ( linksize > 0 ) { | 296 if ( linksize > 0 ) { |
1213 } | 1200 } |
1214 if ( (this->screen->flags & SDL_HWPALETTE) == SDL_HWPALETTE ) { | 1201 if ( (this->screen->flags & SDL_HWPALETTE) == SDL_HWPALETTE ) { |
1215 /* private writable colormap: just set the colours we need */ | 1202 /* private writable colormap: just set the colours we need */ |
1216 XColor *xcmap; | 1203 XColor *xcmap; |
1217 int i; | 1204 int i; |
1218 xcmap = ALLOCA(ncolors*sizeof(*xcmap)); | 1205 xcmap = SDL_stack_alloc(XColor, ncolors); |
1219 if(xcmap == NULL) | 1206 if(xcmap == NULL) |
1220 return 0; | 1207 return 0; |
1221 for ( i=0; i<ncolors; ++i ) { | 1208 for ( i=0; i<ncolors; ++i ) { |
1222 xcmap[i].pixel = i + firstcolor; | 1209 xcmap[i].pixel = i + firstcolor; |
1223 xcmap[i].red = (colors[i].r<<8)|colors[i].r; | 1210 xcmap[i].red = (colors[i].r<<8)|colors[i].r; |
1225 xcmap[i].blue = (colors[i].b<<8)|colors[i].b; | 1212 xcmap[i].blue = (colors[i].b<<8)|colors[i].b; |
1226 xcmap[i].flags = (DoRed|DoGreen|DoBlue); | 1213 xcmap[i].flags = (DoRed|DoGreen|DoBlue); |
1227 } | 1214 } |
1228 pXStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors); | 1215 pXStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors); |
1229 pXSync(GFX_Display, False); | 1216 pXSync(GFX_Display, False); |
1230 FREEA(xcmap); | 1217 SDL_stack_free(xcmap); |
1231 } else { | 1218 } else { |
1232 /* | 1219 /* |
1233 * Shared colormap: We only allocate read-only cells, which | 1220 * Shared colormap: We only allocate read-only cells, which |
1234 * increases the likelyhood of colour sharing with other | 1221 * increases the likelyhood of colour sharing with other |
1235 * clients. The pixel values will almost certainly be | 1222 * clients. The pixel values will almost certainly be |
1243 unsigned long *freelist; | 1230 unsigned long *freelist; |
1244 int i; | 1231 int i; |
1245 int nfree = 0; | 1232 int nfree = 0; |
1246 int nc = this->screen->format->palette->ncolors; | 1233 int nc = this->screen->format->palette->ncolors; |
1247 colors = this->screen->format->palette->colors; | 1234 colors = this->screen->format->palette->colors; |
1248 freelist = ALLOCA(nc * sizeof(*freelist)); | 1235 freelist = SDL_stack_alloc(unsigned long, nc); |
1249 /* make sure multiple allocations of the same cell are freed */ | 1236 /* make sure multiple allocations of the same cell are freed */ |
1250 for(i = 0; i < ncolors; i++) { | 1237 for(i = 0; i < ncolors; i++) { |
1251 int pixel = firstcolor + i; | 1238 int pixel = firstcolor + i; |
1252 while(SDL_XPixels[pixel]) { | 1239 while(SDL_XPixels[pixel]) { |
1253 freelist[nfree++] = pixel; | 1240 freelist[nfree++] = pixel; |
1254 --SDL_XPixels[pixel]; | 1241 --SDL_XPixels[pixel]; |
1255 } | 1242 } |
1256 } | 1243 } |
1257 pXFreeColors(GFX_Display, SDL_XColorMap, freelist, nfree, 0); | 1244 pXFreeColors(GFX_Display, SDL_XColorMap, freelist, nfree, 0); |
1258 FREEA(freelist); | 1245 SDL_stack_free(freelist); |
1259 | 1246 |
1260 want = ALLOCA(ncolors * sizeof(SDL_Color)); | 1247 want = SDL_stack_alloc(SDL_Color, ncolors); |
1261 reject = ALLOCA(ncolors * sizeof(SDL_Color)); | 1248 reject = SDL_stack_alloc(SDL_Color, ncolors); |
1262 SDL_memcpy(want, colors + firstcolor, ncolors * sizeof(SDL_Color)); | 1249 SDL_memcpy(want, colors + firstcolor, ncolors * sizeof(SDL_Color)); |
1263 /* make sure the user isn't fooled by her own wishes | 1250 /* make sure the user isn't fooled by her own wishes |
1264 (black is safe, always available in the default colormap) */ | 1251 (black is safe, always available in the default colormap) */ |
1265 SDL_memset(colors + firstcolor, 0, ncolors * sizeof(SDL_Color)); | 1252 SDL_memset(colors + firstcolor, 0, ncolors * sizeof(SDL_Color)); |
1266 | 1253 |
1286 reject[nrej++] = want[i]; | 1273 reject[nrej++] = want[i]; |
1287 } | 1274 } |
1288 } | 1275 } |
1289 if(nrej) | 1276 if(nrej) |
1290 allocate_nearest(this, colors, reject, nrej); | 1277 allocate_nearest(this, colors, reject, nrej); |
1291 FREEA(reject); | 1278 SDL_stack_free(reject); |
1292 FREEA(want); | 1279 SDL_stack_free(want); |
1293 } | 1280 } |
1294 return nrej == 0; | 1281 return nrej == 0; |
1295 } | 1282 } |
1296 | 1283 |
1297 int X11_SetGammaRamp(_THIS, Uint16 *ramp) | 1284 int X11_SetGammaRamp(_THIS, Uint16 *ramp) |