Mercurial > sdl-ios-xcode
comparison src/joystick/SDL_joystick.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 |
---|---|
49 | 49 |
50 SDL_numjoysticks = 0; | 50 SDL_numjoysticks = 0; |
51 status = SDL_SYS_JoystickInit(); | 51 status = SDL_SYS_JoystickInit(); |
52 if ( status >= 0 ) { | 52 if ( status >= 0 ) { |
53 arraylen = (status+1)*sizeof(*SDL_joysticks); | 53 arraylen = (status+1)*sizeof(*SDL_joysticks); |
54 SDL_joysticks = (SDL_Joystick **)malloc(arraylen); | 54 SDL_joysticks = (SDL_Joystick **)SDL_malloc(arraylen); |
55 if ( SDL_joysticks == NULL ) { | 55 if ( SDL_joysticks == NULL ) { |
56 SDL_numjoysticks = 0; | 56 SDL_numjoysticks = 0; |
57 } else { | 57 } else { |
58 memset(SDL_joysticks, 0, arraylen); | 58 SDL_memset(SDL_joysticks, 0, arraylen); |
59 SDL_numjoysticks = status; | 59 SDL_numjoysticks = status; |
60 } | 60 } |
61 status = 0; | 61 status = 0; |
62 } | 62 } |
63 default_joystick = NULL; | 63 default_joystick = NULL; |
111 return(joystick); | 111 return(joystick); |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 /* Create and initialize the joystick */ | 115 /* Create and initialize the joystick */ |
116 joystick = (SDL_Joystick *)malloc((sizeof *joystick)); | 116 joystick = (SDL_Joystick *)SDL_malloc((sizeof *joystick)); |
117 if ( joystick != NULL ) { | 117 if ( joystick != NULL ) { |
118 memset(joystick, 0, (sizeof *joystick)); | 118 SDL_memset(joystick, 0, (sizeof *joystick)); |
119 joystick->index = device_index; | 119 joystick->index = device_index; |
120 if ( SDL_SYS_JoystickOpen(joystick) < 0 ) { | 120 if ( SDL_SYS_JoystickOpen(joystick) < 0 ) { |
121 free(joystick); | 121 SDL_free(joystick); |
122 joystick = NULL; | 122 joystick = NULL; |
123 } else { | 123 } else { |
124 if ( joystick->naxes > 0 ) { | 124 if ( joystick->naxes > 0 ) { |
125 joystick->axes = (Sint16 *)malloc | 125 joystick->axes = (Sint16 *)SDL_malloc |
126 (joystick->naxes*sizeof(Sint16)); | 126 (joystick->naxes*sizeof(Sint16)); |
127 } | 127 } |
128 if ( joystick->nhats > 0 ) { | 128 if ( joystick->nhats > 0 ) { |
129 joystick->hats = (Uint8 *)malloc | 129 joystick->hats = (Uint8 *)SDL_malloc |
130 (joystick->nhats*sizeof(Uint8)); | 130 (joystick->nhats*sizeof(Uint8)); |
131 } | 131 } |
132 if ( joystick->nballs > 0 ) { | 132 if ( joystick->nballs > 0 ) { |
133 joystick->balls = (struct balldelta *)malloc | 133 joystick->balls = (struct balldelta *)SDL_malloc |
134 (joystick->nballs*sizeof(*joystick->balls)); | 134 (joystick->nballs*sizeof(*joystick->balls)); |
135 } | 135 } |
136 if ( joystick->nbuttons > 0 ) { | 136 if ( joystick->nbuttons > 0 ) { |
137 joystick->buttons = (Uint8 *)malloc | 137 joystick->buttons = (Uint8 *)SDL_malloc |
138 (joystick->nbuttons*sizeof(Uint8)); | 138 (joystick->nbuttons*sizeof(Uint8)); |
139 } | 139 } |
140 if ( ((joystick->naxes > 0) && !joystick->axes) | 140 if ( ((joystick->naxes > 0) && !joystick->axes) |
141 || ((joystick->nhats > 0) && !joystick->hats) | 141 || ((joystick->nhats > 0) && !joystick->hats) |
142 || ((joystick->nballs > 0) && !joystick->balls) | 142 || ((joystick->nballs > 0) && !joystick->balls) |
144 SDL_OutOfMemory(); | 144 SDL_OutOfMemory(); |
145 SDL_JoystickClose(joystick); | 145 SDL_JoystickClose(joystick); |
146 joystick = NULL; | 146 joystick = NULL; |
147 } | 147 } |
148 if ( joystick->axes ) { | 148 if ( joystick->axes ) { |
149 memset(joystick->axes, 0, | 149 SDL_memset(joystick->axes, 0, |
150 joystick->naxes*sizeof(Sint16)); | 150 joystick->naxes*sizeof(Sint16)); |
151 } | 151 } |
152 if ( joystick->hats ) { | 152 if ( joystick->hats ) { |
153 memset(joystick->hats, 0, | 153 SDL_memset(joystick->hats, 0, |
154 joystick->nhats*sizeof(Uint8)); | 154 joystick->nhats*sizeof(Uint8)); |
155 } | 155 } |
156 if ( joystick->balls ) { | 156 if ( joystick->balls ) { |
157 memset(joystick->balls, 0, | 157 SDL_memset(joystick->balls, 0, |
158 joystick->nballs*sizeof(*joystick->balls)); | 158 joystick->nballs*sizeof(*joystick->balls)); |
159 } | 159 } |
160 if ( joystick->buttons ) { | 160 if ( joystick->buttons ) { |
161 memset(joystick->buttons, 0, | 161 SDL_memset(joystick->buttons, 0, |
162 joystick->nbuttons*sizeof(Uint8)); | 162 joystick->nbuttons*sizeof(Uint8)); |
163 } | 163 } |
164 } | 164 } |
165 } | 165 } |
166 if ( joystick ) { | 166 if ( joystick ) { |
373 SDL_SYS_JoystickClose(joystick); | 373 SDL_SYS_JoystickClose(joystick); |
374 | 374 |
375 /* Remove joystick from list */ | 375 /* Remove joystick from list */ |
376 for ( i=0; SDL_joysticks[i]; ++i ) { | 376 for ( i=0; SDL_joysticks[i]; ++i ) { |
377 if ( joystick == SDL_joysticks[i] ) { | 377 if ( joystick == SDL_joysticks[i] ) { |
378 memcpy(&SDL_joysticks[i], &SDL_joysticks[i+1], | 378 SDL_memcpy(&SDL_joysticks[i], &SDL_joysticks[i+1], |
379 (SDL_numjoysticks-i)*sizeof(joystick)); | 379 (SDL_numjoysticks-i)*sizeof(joystick)); |
380 break; | 380 break; |
381 } | 381 } |
382 } | 382 } |
383 | 383 |
384 /* Let the event thread keep running */ | 384 /* Let the event thread keep running */ |
385 SDL_Unlock_EventThread(); | 385 SDL_Unlock_EventThread(); |
386 | 386 |
387 /* Free the data associated with this joystick */ | 387 /* Free the data associated with this joystick */ |
388 if ( joystick->axes ) { | 388 if ( joystick->axes ) { |
389 free(joystick->axes); | 389 SDL_free(joystick->axes); |
390 } | 390 } |
391 if ( joystick->hats ) { | 391 if ( joystick->hats ) { |
392 free(joystick->hats); | 392 SDL_free(joystick->hats); |
393 } | 393 } |
394 if ( joystick->balls ) { | 394 if ( joystick->balls ) { |
395 free(joystick->balls); | 395 SDL_free(joystick->balls); |
396 } | 396 } |
397 if ( joystick->buttons ) { | 397 if ( joystick->buttons ) { |
398 free(joystick->buttons); | 398 SDL_free(joystick->buttons); |
399 } | 399 } |
400 free(joystick); | 400 SDL_free(joystick); |
401 } | 401 } |
402 | 402 |
403 void SDL_JoystickQuit(void) | 403 void SDL_JoystickQuit(void) |
404 { | 404 { |
405 /* Stop the event polling */ | 405 /* Stop the event polling */ |
408 SDL_Unlock_EventThread(); | 408 SDL_Unlock_EventThread(); |
409 | 409 |
410 /* Quit the joystick setup */ | 410 /* Quit the joystick setup */ |
411 SDL_SYS_JoystickQuit(); | 411 SDL_SYS_JoystickQuit(); |
412 if ( SDL_joysticks ) { | 412 if ( SDL_joysticks ) { |
413 free(SDL_joysticks); | 413 SDL_free(SDL_joysticks); |
414 SDL_joysticks = NULL; | 414 SDL_joysticks = NULL; |
415 } | 415 } |
416 } | 416 } |
417 | 417 |
418 | 418 |