comparison src/joystick/bsd/SDL_sysjoystick.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 c9b51268668f
children 604d73db6802
comparison
equal deleted inserted replaced
1335:c39265384763 1336:3692456e7b0f
137 char s[16]; 137 char s[16];
138 int i, fd; 138 int i, fd;
139 139
140 SDL_numjoysticks = 0; 140 SDL_numjoysticks = 0;
141 141
142 memset(joynames, 0, sizeof(joynames)); 142 SDL_memset(joynames, 0, sizeof(joynames));
143 memset(joydevnames, 0, sizeof(joydevnames)); 143 SDL_memset(joydevnames, 0, sizeof(joydevnames));
144 144
145 for (i = 0; i < MAX_UHID_JOYS; i++) { 145 for (i = 0; i < MAX_UHID_JOYS; i++) {
146 SDL_Joystick nj; 146 SDL_Joystick nj;
147 147
148 sprintf(s, "/dev/uhid%d", i); 148 sprintf(s, "/dev/uhid%d", i);
152 152
153 if (SDL_SYS_JoystickOpen(&nj) == 0) { 153 if (SDL_SYS_JoystickOpen(&nj) == 0) {
154 SDL_SYS_JoystickClose(&nj); 154 SDL_SYS_JoystickClose(&nj);
155 SDL_numjoysticks++; 155 SDL_numjoysticks++;
156 } else { 156 } else {
157 free(joynames[nj.index]); 157 SDL_free(joynames[nj.index]);
158 joynames[nj.index] = NULL; 158 joynames[nj.index] = NULL;
159 } 159 }
160 } 160 }
161 for (i = 0; i < MAX_JOY_JOYS; i++) { 161 for (i = 0; i < MAX_JOY_JOYS; i++) {
162 sprintf(s, "/dev/joy%d", i); 162 sprintf(s, "/dev/joy%d", i);
239 if (fd == -1) { 239 if (fd == -1) {
240 SDL_SetError("%s: %s", path, strerror(errno)); 240 SDL_SetError("%s: %s", path, strerror(errno));
241 return (-1); 241 return (-1);
242 } 242 }
243 243
244 hw = (struct joystick_hwdata *)malloc(sizeof(struct joystick_hwdata)); 244 hw = (struct joystick_hwdata *)SDL_malloc(sizeof(struct joystick_hwdata));
245 if (hw == NULL) { 245 if (hw == NULL) {
246 SDL_OutOfMemory(); 246 SDL_OutOfMemory();
247 close(fd); 247 close(fd);
248 return (-1); 248 return (-1);
249 } 249 }
250 joy->hwdata = hw; 250 joy->hwdata = hw;
251 hw->fd = fd; 251 hw->fd = fd;
252 hw->path = strdup(path); 252 hw->path = strdup(path);
253 if (! strncmp(path, "/dev/joy", 8)) { 253 if (! SDL_strncmp(path, "/dev/joy", 8)) {
254 hw->type = BSDJOY_JOY; 254 hw->type = BSDJOY_JOY;
255 joy->naxes = 2; 255 joy->naxes = 2;
256 joy->nbuttons = 2; 256 joy->nbuttons = 2;
257 joy->nhats = 0; 257 joy->nhats = 0;
258 joy->nballs = 0; 258 joy->nballs = 0;
309 case HUP_GENERIC_DESKTOP: 309 case HUP_GENERIC_DESKTOP:
310 switch (HID_USAGE(hitem.usage)) { 310 switch (HID_USAGE(hitem.usage)) {
311 case HUG_JOYSTICK: 311 case HUG_JOYSTICK:
312 case HUG_GAME_PAD: 312 case HUG_GAME_PAD:
313 s = hid_usage_in_page(hitem.usage); 313 s = hid_usage_in_page(hitem.usage);
314 sp = malloc(strlen(s) + 5); 314 sp = SDL_malloc(SDL_strlen(s) + 5);
315 sprintf(sp, "%s (%d)", s, 315 sprintf(sp, "%s (%d)", s,
316 joy->index); 316 joy->index);
317 joydevnames[joy->index] = sp; 317 joydevnames[joy->index] = sp;
318 } 318 }
319 } 319 }
349 fcntl(fd, F_SETFL, O_NONBLOCK); 349 fcntl(fd, F_SETFL, O_NONBLOCK);
350 350
351 return (0); 351 return (0);
352 usberr: 352 usberr:
353 close(hw->fd); 353 close(hw->fd);
354 free(hw->path); 354 SDL_free(hw->path);
355 free(hw); 355 SDL_free(hw);
356 return (-1); 356 return (-1);
357 } 357 }
358 358
359 void 359 void
360 SDL_SYS_JoystickUpdate(SDL_Joystick *joy) 360 SDL_SYS_JoystickUpdate(SDL_Joystick *joy)
480 480
481 /* Function to close a joystick after use */ 481 /* Function to close a joystick after use */
482 void 482 void
483 SDL_SYS_JoystickClose(SDL_Joystick *joy) 483 SDL_SYS_JoystickClose(SDL_Joystick *joy)
484 { 484 {
485 if (strncmp(joy->hwdata->path, "/dev/joy", 8)) { 485 if (SDL_strncmp(joy->hwdata->path, "/dev/joy", 8)) {
486 report_free(&joy->hwdata->inreport); 486 report_free(&joy->hwdata->inreport);
487 hid_dispose_report_desc(joy->hwdata->repdesc); 487 hid_dispose_report_desc(joy->hwdata->repdesc);
488 } 488 }
489 close(joy->hwdata->fd); 489 close(joy->hwdata->fd);
490 free(joy->hwdata->path); 490 SDL_free(joy->hwdata->path);
491 free(joy->hwdata); 491 SDL_free(joy->hwdata);
492 492
493 return; 493 return;
494 } 494 }
495 495
496 void 496 void
498 { 498 {
499 int i; 499 int i;
500 500
501 for (i = 0; i < MAX_JOYS; i++) { 501 for (i = 0; i < MAX_JOYS; i++) {
502 if (joynames[i] != NULL) 502 if (joynames[i] != NULL)
503 free(joynames[i]); 503 SDL_free(joynames[i]);
504 if (joydevnames[i] != NULL) 504 if (joydevnames[i] != NULL)
505 free(joydevnames[i]); 505 SDL_free(joydevnames[i]);
506 } 506 }
507 507
508 return; 508 return;
509 } 509 }
510 510
536 return (-1); 536 return (-1);
537 } 537 }
538 r->size = len; 538 r->size = len;
539 539
540 if (r->size > 0) { 540 if (r->size > 0) {
541 r->buf = malloc(sizeof(*r->buf) - sizeof(REP_BUF_DATA(r)) + 541 r->buf = SDL_malloc(sizeof(*r->buf) - sizeof(REP_BUF_DATA(r)) +
542 r->size); 542 r->size);
543 if (r->buf == NULL) { 543 if (r->buf == NULL) {
544 SDL_OutOfMemory(); 544 SDL_OutOfMemory();
545 return (-1); 545 return (-1);
546 } 546 }
554 554
555 static void 555 static void
556 report_free(struct report *r) 556 report_free(struct report *r)
557 { 557 {
558 if (r->buf != NULL) { 558 if (r->buf != NULL) {
559 free(r->buf); 559 SDL_free(r->buf);
560 } 560 }
561 r->status = SREPORT_UNINIT; 561 r->status = SREPORT_UNINIT;
562 } 562 }
563 563