summaryrefslogtreecommitdiff
path: root/extras/usb_id/usb_id.c
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2010-03-17 17:42:35 +0100
committerKay Sievers <kay.sievers@vrfy.org>2010-03-17 17:42:35 +0100
commitfc8d61c53d6c181dc1e9f5a23c0f805c32a392af (patch)
tree68c9021843905d0fda089b480d131fa26dcd98cb /extras/usb_id/usb_id.c
parent578cc8a8085a47c963b5940459e475ac5f07219c (diff)
libudev: add udev_device_new_from_environment()
Diffstat (limited to 'extras/usb_id/usb_id.c')
-rw-r--r--extras/usb_id/usb_id.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/extras/usb_id/usb_id.c b/extras/usb_id/usb_id.c
index b412598d35..42ccddff35 100644
--- a/extras/usb_id/usb_id.c
+++ b/extras/usb_id/usb_id.c
@@ -456,8 +456,6 @@ int main(int argc, char **argv)
};
struct udev *udev;
struct udev_device *dev = NULL;
- char syspath[UTIL_PATH_SIZE];
- const char *devpath;
static int export;
int retval = 0;
@@ -492,7 +490,7 @@ int main(int argc, char **argv)
export = 1;
break;
case 'h':
- printf("Usage: usb_id [--usb-info] [--num-info] [--export] [--help] <devpath>\n"
+ printf("Usage: usb_id [--usb-info] [--num-info] [--export] [--help] [<devpath>]\n"
" --usb-info use usb strings instead\n"
" --num-info use numerical values\n"
" --export print values as environment keys\n"
@@ -503,18 +501,26 @@ int main(int argc, char **argv)
}
}
- devpath = argv[optind];
- if (devpath == NULL) {
- fprintf(stderr, "No device specified\n");
- retval = 1;
- goto exit;
- }
-
- util_strscpyl(syspath, sizeof(syspath), udev_get_sys_path(udev), devpath, NULL);
- dev = udev_device_new_from_syspath(udev, syspath);
+ dev = udev_device_new_from_environment(udev);
if (dev == NULL) {
- err(udev, "unable to access '%s'\n", devpath);
- return 1;
+ char syspath[UTIL_PATH_SIZE];
+ const char *devpath;
+
+ devpath = argv[optind];
+ if (devpath == NULL) {
+ fprintf(stderr, "missing device\n");
+ retval = 1;
+ goto exit;
+ }
+
+ util_strscpyl(syspath, sizeof(syspath), udev_get_sys_path(udev), devpath, NULL);
+ dev = udev_device_new_from_syspath(udev, syspath);
+ if (dev == NULL) {
+ err(udev, "unable to access '%s'\n", devpath);
+ retval = 1;
+ goto exit;
+ return 1;
+ }
}
retval = usb_id(dev);