chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge rsync://rsync.kernel.org/pub/scm/linux/hotplug/udev
[elogind.git]
/
extras
/
usb_id
/
usb_id.c
diff --git
a/extras/usb_id/usb_id.c
b/extras/usb_id/usb_id.c
index f4011ee8992b06dec55ed707d9d2a9fdc44976a2..f5ee7959246a8d3a93653497ad0441988915aba7 100644
(file)
--- a/
extras/usb_id/usb_id.c
+++ b/
extras/usb_id/usb_id.c
@@
-76,10
+76,9
@@
static int use_num_info;
static int export;
static int debug;
static int export;
static int debug;
-static void set_str(char *to, const
unsigned char *from, in
t count)
+static void set_str(char *to, const
char *from, size_
t count)
{
{
- int i, j;
- int len;
+ size_t i, j, len;
/* strip trailing whitespace */
len = strnlen(from, count);
/* strip trailing whitespace */
len = strnlen(from, count);
@@
-120,25
+119,26
@@
static void set_str(char *to, const unsigned char *from, int count)
*
* Set the type based on the USB interface class
*/
*
* Set the type based on the USB interface class
*/
-static void set_usb_iftype(char *to, const char *from,
int count
)
+static void set_usb_iftype(char *to, const char *from,
size_t len
)
{
int type_num;
char *eptr;
{
int type_num;
char *eptr;
+ char *type = "generic";
type_num = strtoul(from, &eptr, 0);
if (eptr != from) {
switch (type_num) {
case 1:
type_num = strtoul(from, &eptr, 0);
if (eptr != from) {
switch (type_num) {
case 1:
-
sprintf(to, "audio")
;
+
type = "audio"
;
break;
case 3:
break;
case 3:
-
sprintf(to, "hid")
;
+
type = "hid"
;
break;
case 7:
break;
case 7:
-
sprintf(to, "printer")
;
+
type = "printer"
;
break;
case 8:
break;
case 8:
-
sprintf(to, "disk")
;
+
type = "disk"
;
break;
case 2: /* CDC-Control */
case 5: /* Physical */
break;
case 2: /* CDC-Control */
case 5: /* Physical */
@@
-153,12
+153,11
@@
static void set_usb_iftype(char *to, const char *from, int count)
case 0xf2: /* Application-specific */
case 0xff: /* Vendor-specific */
default:
case 0xf2: /* Application-specific */
case 0xff: /* Vendor-specific */
default:
- sprintf(to, "generic");
break;
}
break;
}
- } else {
- sprintf(to, "generic");
}
}
+ strncpy(to, type, len);
+ to[len-1] = '\0';
}
/*
}
/*
@@
-167,32
+166,35
@@
static void set_usb_iftype(char *to, const char *from, int count)
* Set the type base on the interfaceSubClass.
* Valid for Mass-Storage devices (type 8) only.
*/
* Set the type base on the interfaceSubClass.
* Valid for Mass-Storage devices (type 8) only.
*/
-static int set_usb_ifsubtype(char *to, const char *from,
int count
)
+static int set_usb_ifsubtype(char *to, const char *from,
size_t len
)
{
int type_num = 0;
char *eptr;
{
int type_num = 0;
char *eptr;
+ char *type = "generic";
type_num = strtoul(from, &eptr, 0);
if (eptr != from) {
switch (type_num) {
case 2:
type_num = strtoul(from, &eptr, 0);
if (eptr != from) {
switch (type_num) {
case 2:
-
sprintf(to, "cd")
;
+
type = "cd"
;
break;
case 3:
break;
case 3:
-
sprintf(to, "tape")
;
+
type = "tape"
;
break;
case 4: /* UFI */
case 5: /* SFF-8070i */
break;
case 4: /* UFI */
case 5: /* SFF-8070i */
-
sprintf(to, "floppy")
;
+
type = "floppy"
;
break;
case 1: /* RBC devices */
case 6: /* Transparent SPC-2 devices */
break;
case 1: /* RBC devices */
case 6: /* Transparent SPC-2 devices */
- sprintf(to, "disk");
+ type = "disk";
+ break;
+ default:
break;
}
break;
}
- } else {
- sprintf(to, "generic");
}
}
+ strncpy(to, type, len);
+ to[len-1] = '\0';
return type_num;
}
return type_num;
}
@@
-316,11
+318,11
@@
static int usb_id(const char *target_path)
/* usb device directory */
usb_dev = sysfs_get_device_parent(interface_dev);
/* usb device directory */
usb_dev = sysfs_get_device_parent(interface_dev);
- if (
!strcmp(interface_dev->bus, "bus
") != 0) {
+ if (
strcmp(interface_dev->bus, "usb
") != 0) {
info("%s is not an usb device", target_path);
return 1;
}
info("%s is not an usb device", target_path);
return 1;
}
-
+
if_class = sysfs_get_device_attr(interface_dev, "bInterfaceClass");
if (!if_class) {
info("%s: cannot get bInterfaceClass attribute", interface_dev->name);
if_class = sysfs_get_device_attr(interface_dev, "bInterfaceClass");
if (!if_class) {
info("%s: cannot get bInterfaceClass attribute", interface_dev->name);
@@
-485,6
+487,7
@@
int main(int argc, char **argv)
vendor_str, model_str, serial_str);
}
printf("ID_TYPE=%s\n", type_str);
vendor_str, model_str, serial_str);
}
printf("ID_TYPE=%s\n", type_str);
+ printf("ID_BUS=usb\n");
} else {
if (serial_str[0] == '\0') {
printf("%s_%s\n",
} else {
if (serial_str[0] == '\0') {
printf("%s_%s\n",
@@
-497,6
+500,3
@@
int main(int argc, char **argv)
}
exit(retval);
}
}
exit(retval);
}
-
-
-