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

Commit

Permalink
Using errno for more verbosity in errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbens committed Jul 3, 2008
1 parent 1ee2ff1 commit 2d78f41
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/haptic/linux/SDL_syshaptic.c
Expand Up @@ -37,6 +37,7 @@
#include <fcntl.h>
#include <linux/limits.h>
#include <string.h>
#include <errno.h>


#define MAX_HAPTICS 32
Expand Down Expand Up @@ -88,7 +89,7 @@ EV_IsHaptic(int fd)
ret = 0;

if (ioctl(fd, EVIOCGBIT(EV_FF, sizeof(unsigned long) * 4), features) < 0) {
SDL_SetError("Unable to get device's haptic abilities.");
SDL_SetError("Unable to get device's haptic abilities: %s", strerror(errno));
return -1;
}

Expand Down Expand Up @@ -212,7 +213,7 @@ SDL_SYS_HapticOpenFromFD(SDL_Haptic * haptic, int fd)

/* Set the effects */
if (ioctl(fd, EVIOCGEFFECTS, &haptic->neffects) < 0) {
SDL_SetError("Unable to query haptic device memory.");
SDL_SetError("Unable to query haptic device memory: %s", strerror(errno));
goto open_err;
}
haptic->effects = (struct haptic_effect *)
Expand Down Expand Up @@ -249,7 +250,8 @@ SDL_SYS_HapticOpen(SDL_Haptic * haptic)
/* Open the character device */
fd = open(SDL_hapticlist[haptic->index].fname, O_RDWR, 0);
if (fd < 0) {
SDL_SetError("Unable to open %s\n", SDL_hapticlist[haptic->index]);
SDL_SetError("Unable to open %s: %s",
SDL_hapticlist[haptic->index], strerror(errno));
return -1;
}

Expand Down Expand Up @@ -477,7 +479,7 @@ SDL_SYS_ToFFEffect( struct ff_effect * dest, SDL_HapticEffect * src )


default:
SDL_SetError("Unknown haptic effect type.");
SDL_SetError("Unknown haptic effect type");
return -1;
}

Expand Down Expand Up @@ -511,7 +513,7 @@ SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect * effect,

/* Upload the effect */
if (ioctl(haptic->hwdata->fd, EVIOCSFF, linux_effect) < 0) {
SDL_SetError("Error uploading effect to the haptic device.");
SDL_SetError("Error uploading effect to the haptic device: %s", strerror(errno));
goto new_effect_err;
}

Expand Down Expand Up @@ -543,7 +545,7 @@ int SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,

/* See if it can be uploaded. */
if (ioctl(haptic->hwdata->fd, EVIOCSFF, &linux_effect) < 0) {
SDL_SetError("Error updating the haptic effect.");
SDL_SetError("Error updating the haptic effect: %s", strerror(errno));
return -1;
}

Expand All @@ -568,7 +570,7 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
run.value = 1;

if (write(haptic->hwdata->fd, (const void*) &run, sizeof(run)) < 0) {
SDL_SetError("Unable to run the haptic effect.");
SDL_SetError("Unable to run the haptic effect: %s", strerror(errno));
return -1;
}

Expand All @@ -589,7 +591,7 @@ SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
stop.value = 0;

if (write(haptic->hwdata->fd, (const void*) &stop, sizeof(stop)) < 0) {
SDL_SetError("Unable to stop the haptic effect.");
SDL_SetError("Unable to stop the haptic effect: %s", strerror(errno));
return -1;
}

Expand All @@ -604,7 +606,8 @@ void
SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
{
if (ioctl(haptic->hwdata->fd, EVIOCRMFF, effect->hweffect->effect.id) < 0) {
SDL_SetError("Error removing the effect from the haptic device.");
SDL_SetError("Error removing the effect from the haptic device: %s",
strerror(errno));
}
SDL_free(effect->hweffect);
effect->hweffect = NULL;
Expand Down Expand Up @@ -649,7 +652,7 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
ie.value = (0xFFFFUL * gain) / 100;

if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
SDL_SetError("Error setting gain.");
SDL_SetError("Error setting gain: %s", strerror(errno));
return -1;
}

Expand All @@ -670,7 +673,7 @@ SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
ie.value = (0xFFFFUL * autocenter) / 100;

if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
SDL_SetError("Error setting autocenter.");
SDL_SetError("Error setting autocenter: %s", strerror(errno));
return -1;
}

Expand Down

0 comments on commit 2d78f41

Please sign in to comment.