little clarification
[hband-tools.git] / compiled-tools / usbreset.c
blob5f069ac3e3ff0d69766aceb8f5ad53e8182327e2
1 /* usbreset -- send a USB port reset to a USB device */
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <fcntl.h>
6 #include <errno.h>
7 #include <sys/ioctl.h>
9 #include <linux/usbdevice_fs.h>
12 int main(int argc, char **argv)
14 const char *filename;
15 int fd;
16 int rc;
18 if (argc != 2) {
19 fprintf(stderr, "Usage: usbreset device-filename\n");
20 return 1;
22 filename = argv[1];
24 fd = open(filename, O_WRONLY);
25 if (fd < 0) {
26 perror("Error opening output file");
27 return 1;
30 printf("Resetting USB device %s\n", filename);
31 rc = ioctl(fd, USBDEVFS_RESET, 0);
32 if (rc < 0) {
33 perror("Error in ioctl");
34 return 1;
36 printf("Reset successful\n");
38 close(fd);
39 return 0;