Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
More verbosity and error checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbens committed Feb 21, 2009
1 parent 8bea68c commit 65b7eae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/haptic/SDL_haptic.c
Expand Up @@ -66,13 +66,20 @@ ValidHaptic(SDL_Haptic * haptic)
int valid;

valid = 0;
for (i = 0; i < SDL_numhaptics; i++) {
if (SDL_haptics[i] == haptic) {
valid = 1;
break;
if (haptic != NULL) {
for (i = 0; i < SDL_numhaptics; i++) {
if (SDL_haptics[i] == haptic) {
valid = 1;
break;
}
}
}

/* Create the error here. */
if (valid == 0) {
SDL_SetError("Haptic: Invalid haptic device identifier");
}

return valid;
}

Expand Down
11 changes: 11 additions & 0 deletions src/haptic/linux/SDL_syshaptic.c
Expand Up @@ -395,17 +395,28 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
int fd;
int ret;


/* Find the joystick in the haptic list. */
for (i = 0; i < MAX_HAPTICS; i++) {
if (SDL_hapticlist[i].fname != NULL) {
if (SDL_strcmp(SDL_hapticlist[i].fname, joystick->hwdata->fname)
== 0) {
haptic->index = i;
break;
}
}
}
if (i >= MAX_HAPTICS) {
SDL_SetError("Haptic: Joystick doesn't have Haptic capabilities");
return -1;
}

fd = open(joystick->hwdata->fname, O_RDWR, 0);
if (fd < 0) {
SDL_SetError("Haptic: Unable to open %s: %s",
joystick->hwdata->fname, strerror(errno));
return -1;
}
ret = SDL_SYS_HapticOpenFromFD(haptic, fd); /* Already closes on error. */
if (ret < 0) {
return -1;
Expand Down

0 comments on commit 65b7eae

Please sign in to comment.