← Commit list

5e0e54827

Peter Korsgaard
Peter Korsgaard
2023-12-13
SUCCESS Duration: 152s

Subject

util-linux/lsusb.c: print manufacturer/product strings if available

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

util-linux/lsusb.c+27 -1
@@ -24,6 +24,24 @@
#include "libbb.h"
+static char * FAST_FUNC add_sysfs_prop(const char *dir, const char *suffix,
+ char *buf, size_t size)
+{
+ char *filename;
+ ssize_t len;
+
+ filename = concat_path_file(dir, suffix);
+ len = open_read_close(filename, buf, size - 1);
+ free(filename);
+
+ if (len < 0)
+ len = 0;
+
+ buf[len] = '\0';
+
+ return trim(buf);
+}
+
static int FAST_FUNC fileAction(struct recursive_state *state UNUSED_PARAM,
const char *fileName,
struct stat *statbuf UNUSED_PARAM)
@@ -61,7 +79,15 @@ static int FAST_FUNC fileAction(struct recursive_state *state UNUSED_PARAM,
config_close(parser);
if (busnum) {
- printf("Bus %s Device %s: ID %04x:%04x\n", busnum, devnum, product_vid, product_did);
+ char name[256], *p;
+
+ p = add_sysfs_prop(fileName, "/manufacturer", name, sizeof(name) - 1);
+ if (p != name)
+ p = stpcpy(p, " ");
+ add_sysfs_prop(fileName, "/product", p, name + sizeof(name) - p);
+
+ printf("Bus %s Device %s: ID %04x:%04x %s\n", busnum, devnum,
+ product_vid, product_did, name);
free(busnum);
free(devnum);
}