Mercurial > sdl-ios-xcode
comparison src/joystick/linux/SDL_sysjoystick.c @ 2490:be9b206d44af gsoc2008_force_feedback
Some more error checking.
Implemented SDL_HapticOpenFromJoystick().
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Wed, 02 Jul 2008 09:52:44 +0000 |
parents | 96adc8025331 |
children |
comparison
equal
deleted
inserted
replaced
2489:96adc8025331 | 2490:be9b206d44af |
---|---|
772 */ | 772 */ |
773 int | 773 int |
774 SDL_SYS_JoystickOpen(SDL_Joystick * joystick) | 774 SDL_SYS_JoystickOpen(SDL_Joystick * joystick) |
775 { | 775 { |
776 int fd; | 776 int fd; |
777 char *fname; | |
777 SDL_logical_joydecl(int realindex); | 778 SDL_logical_joydecl(int realindex); |
778 SDL_logical_joydecl(SDL_Joystick * realjoy = NULL); | 779 SDL_logical_joydecl(SDL_Joystick * realjoy = NULL); |
779 | 780 |
780 /* Open the joystick and set the joystick file descriptor */ | 781 /* Open the joystick and set the joystick file descriptor */ |
781 #ifndef NO_LOGICAL_JOYSTICKS | 782 #ifndef NO_LOGICAL_JOYSTICKS |
785 | 786 |
786 if (realjoy == NULL) | 787 if (realjoy == NULL) |
787 return (-1); | 788 return (-1); |
788 | 789 |
789 fd = realjoy->hwdata->fd; | 790 fd = realjoy->hwdata->fd; |
791 fname = realjoy->hwdata->fname; | |
790 | 792 |
791 } else { | 793 } else { |
792 fd = open(SDL_joylist[joystick->index].fname, O_RDONLY, 0); | 794 fd = open(SDL_joylist[joystick->index].fname, O_RDONLY, 0); |
795 fname = SDL_joylist[joystick->index].fname; | |
793 } | 796 } |
794 SDL_joylist[joystick->index].joy = joystick; | 797 SDL_joylist[joystick->index].joy = joystick; |
795 #else | 798 #else |
796 fd = open(SDL_joylist[joystick->index].fname, O_RDONLY, 0); | 799 fd = open(SDL_joylist[joystick->index].fname, O_RDONLY, 0); |
800 fname = SDL_joylist[joystick->index].fname; | |
797 #endif | 801 #endif |
798 | 802 |
799 if (fd < 0) { | 803 if (fd < 0) { |
800 SDL_SetError("Unable to open %s\n", SDL_joylist[joystick->index]); | 804 SDL_SetError("Unable to open %s\n", SDL_joylist[joystick->index]); |
801 return (-1); | 805 return (-1); |
807 close(fd); | 811 close(fd); |
808 return (-1); | 812 return (-1); |
809 } | 813 } |
810 SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); | 814 SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); |
811 joystick->hwdata->fd = fd; | 815 joystick->hwdata->fd = fd; |
816 joystick->hwdata->fname = fname; | |
812 | 817 |
813 /* Set the joystick to non-blocking read mode */ | 818 /* Set the joystick to non-blocking read mode */ |
814 fcntl(fd, F_SETFL, O_NONBLOCK); | 819 fcntl(fd, F_SETFL, O_NONBLOCK); |
815 | 820 |
816 /* Get the number of buttons and axes on the joystick */ | 821 /* Get the number of buttons and axes on the joystick */ |