diff options
author | Ondrej Čerman <ondrej.cerman@gmail.com> | 2019-07-26 20:57:25 +0200 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2019-07-29 19:44:04 -0700 |
commit | bc1b620dc15153dad08065eb8af0fc84374a3d76 (patch) | |
tree | af4c35514597469d6c13d344ce4ecd977cf1bdfc /hardinfo | |
parent | 5f620001a8f9017449d15b1a4aafdb9a61a44d4d (diff) |
usb: sorted sysfs usb devices list
Diffstat (limited to 'hardinfo')
-rw-r--r-- | hardinfo/usb_util.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/hardinfo/usb_util.c b/hardinfo/usb_util.c index 59ccab5c..562fa8f5 100644 --- a/hardinfo/usb_util.c +++ b/hardinfo/usb_util.c @@ -92,6 +92,40 @@ static int usbd_list_append(usbd *l, usbd *n) { return c; } +/* returns new top of the list */ +static usbd *usbd_list_append_sorted(usbd *l, usbd *n) { + usbd *b = NULL; + usbd *t = l; + + if (n == NULL) + return l; + + while(l != NULL) { + if ((n->bus > l->bus) || + ((n->bus == l->bus) && (n->dev >= l->dev))) { + if (l->next == NULL) { + l->next = n; + break; + } + b = l; + l = l->next; + } + else { + if (b == NULL) { + t = n; + n->next = l; + } + else { + b->next = n; + n->next = l; + } + break; + } + } + + return t; +} + void usbd_append_interface(usbd *dev, usbi *new_if){ usbi *curr_if; if (dev->if_list == NULL){ @@ -352,7 +386,7 @@ static usbd *usb_get_device_list_sysfs() { if (head == NULL) { head = nd; } else { - usbd_list_append(head, nd); + head = usbd_list_append_sorted(head, nd); } } g_free(devpath); |