FreeCalypso > hg > fc-usbser-tools
annotate libuwrap/find_busdev.c @ 105:1e820ed0904e
Installed-binaries: list of binaries installed by this package
I am establishing a new convention for all FreeCalypso tools, across
different packages and source repositories: each FC tools package
will have a file name Installed-binaries listing all user-invokable
binaries that package installs in /opt/freecalypso/bin. These files
are to serve as an aid to users and distro package maintainers who
prefer to not add /opt/freecalypso/bin to their PATH. The alternative
to adding this directory to PATH is to create a symlink for every
installed binary in some standard location such as /usr/bin or
/usr/local/bin, pointing to the actual binary in /opt/freecalypso/bin;
having a list of all FC-installed binaries in a standardized format
will allow this process to be automated.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 29 Sep 2023 19:42:53 +0000 |
parents | fd3fcba5a8ac |
children |
rev | line source |
---|---|
9 | 1 /* |
2 * In this module we implement the function that locates a USB device | |
10
fd3fcba5a8ac
libuwrap: implement locating by bus/dev
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
3 * by bus and device number/filename strings. |
9 | 4 */ |
5 | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <strings.h> | |
10 #include <usb.h> | |
11 #include "find_dev.h" | |
12 #include "prelim_init.h" | |
13 | |
10
fd3fcba5a8ac
libuwrap: implement locating by bus/dev
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
14 struct usb_device * |
fd3fcba5a8ac
libuwrap: implement locating by bus/dev
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
15 find_usbdev_by_busdev(const char *bus_dev_spec) |
9 | 16 { |
10
fd3fcba5a8ac
libuwrap: implement locating by bus/dev
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
17 const char *slash; |
fd3fcba5a8ac
libuwrap: implement locating by bus/dev
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
18 unsigned bus_name_len; |
fd3fcba5a8ac
libuwrap: implement locating by bus/dev
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
19 struct usb_bus *bus; |
fd3fcba5a8ac
libuwrap: implement locating by bus/dev
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
20 struct usb_device *dev; |
9 | 21 |
10
fd3fcba5a8ac
libuwrap: implement locating by bus/dev
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
22 slash = index(bus_dev_spec, '/'); |
fd3fcba5a8ac
libuwrap: implement locating by bus/dev
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
23 if (!slash) { |
fd3fcba5a8ac
libuwrap: implement locating by bus/dev
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
24 fprintf(stderr, |
fd3fcba5a8ac
libuwrap: implement locating by bus/dev
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
25 "error: bus/dev path expected, but no slash found\n"); |
9 | 26 exit(1); |
27 } | |
10
fd3fcba5a8ac
libuwrap: implement locating by bus/dev
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
28 bus_name_len = slash - bus_dev_spec; |
9 | 29 libusb_prelim_init(); |
30 for (bus = usb_get_busses(); bus; bus = bus->next) { | |
10
fd3fcba5a8ac
libuwrap: implement locating by bus/dev
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
31 if (strlen(bus->dirname) != bus_name_len) |
fd3fcba5a8ac
libuwrap: implement locating by bus/dev
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
32 continue; |
fd3fcba5a8ac
libuwrap: implement locating by bus/dev
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
33 if (strncmp(bus->dirname, bus_dev_spec, bus_name_len)) |
fd3fcba5a8ac
libuwrap: implement locating by bus/dev
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
34 continue; |
9 | 35 for (dev = bus->devices; dev; dev = dev->next) { |
10
fd3fcba5a8ac
libuwrap: implement locating by bus/dev
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
36 if (!strcmp(dev->filename, slash + 1)) |
fd3fcba5a8ac
libuwrap: implement locating by bus/dev
Mychaela Falconia <falcon@freecalypso.org>
parents:
9
diff
changeset
|
37 return dev; |
9 | 38 } |
39 } | |
40 return 0; | |
41 } |