Skip to content

Commit

Permalink
accept devices in form of "/dev/ttyUSB0" and "ttyUSB0"
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrovski committed Oct 8, 2015
1 parent fae037b commit 9bee506
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion util.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ int open_device(char * device_name, int * dev_fd)
return ret;
}

// check for leading /dev/

char * lastSlash = rindex(device_name, '/');
if(lastSlash && !strncmp(device_name, "/dev", lastSlash - device_name)){
device_name = lastSlash + 1;
}

/*
* First, check if /sys/class/tty/<name>/ exists.
*/
Expand All @@ -190,7 +197,7 @@ int open_device(char * device_name, int * dev_fd)
}

if (!S_ISDIR(s.st_mode)) {
errno = -ENOTDIR;
ret = errno = -ENODEV;
err("%s is not a TTY device.", device_name);
goto Done;
}
Expand Down

0 comments on commit 9bee506

Please sign in to comment.