From 0e4cd0ffb4616d042cb0b37134e2818f713294a4 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 12 Feb 2022 04:10:13 -0600 Subject: [PATCH] Search a path for usb.ids and handle usb.ids.gz via zcat. --- toys/other/lsusb.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/toys/other/lsusb.c b/toys/other/lsusb.c index 6df21aec..f104978d 100644 --- a/toys/other/lsusb.c +++ b/toys/other/lsusb.c @@ -67,14 +67,21 @@ static int list_device(struct dirtree *new) void lsusb_main(void) { - int fd; + char *path = "/etc:/vendor:/usr/share/misc"; + struct string_list *sl; + int fd = -1; // Parse http://www.linux-usb.org/usb.ids file (if available) - if (-1 != (fd = open("/etc/usb.ids", O_RDONLY))) { + if ((sl = find_in_path(path, "usb.ids.gz"))) { + signal(SIGCHLD, SIG_IGN); + xpopen((char *[]){"zcat", sl->str, 0}, &fd, 1); + } else if ((sl = find_in_path(path, "usb.ids"))) fd = xopen(sl->str,O_RDONLY); + if (fd != -1) { FILE *fp = fdopen(fd, "r"); char *s, *ss; struct ids *ids, *tids; + free(sl); while ((s = xgetline(fp))) { fd = estrtol(s, &ss, 16); if (ss == s+4+(*s=='\t') && *ss++==' ') { -- 2.39.2