|
|
e858312 |
diff -up libusb-0.1.12/configure.in.openat libusb-0.1.12/configure.in
|
|
|
e858312 |
--- libusb-0.1.12/configure.in.openat 2006-03-04 03:53:04.000000000 +0100
|
|
|
e858312 |
+++ libusb-0.1.12/configure.in 2007-09-04 08:41:04.000000000 +0200
|
|
|
e858312 |
@@ -188,6 +188,7 @@ AC_CHECK_HEADERS(values.h, AC_DEFINE_UNQ
|
|
|
e858312 |
|
|
|
e858312 |
# Check for some functions
|
|
|
e858312 |
AC_CHECK_FUNCS(memmove)
|
|
|
e858312 |
+AC_CHECK_FUNCS(openat)
|
|
|
e858312 |
|
|
|
e858312 |
if test "$os_support" = "bsd"; then
|
|
|
e858312 |
AC_MSG_CHECKING(if dev/usb/usb.h uses new naming convention)
|
|
|
e858312 |
diff -up libusb-0.1.12/linux.c.openat libusb-0.1.12/linux.c
|
|
|
e858312 |
--- libusb-0.1.12/linux.c.openat 2006-03-04 03:52:46.000000000 +0100
|
|
|
e858312 |
+++ libusb-0.1.12/linux.c 2007-09-04 08:40:27.000000000 +0200
|
|
|
e858312 |
@@ -341,12 +341,10 @@ int usb_os_find_busses(struct usb_bus **
|
|
|
e858312 |
continue;
|
|
|
e858312 |
}
|
|
|
e858312 |
|
|
|
e858312 |
- bus = malloc(sizeof(*bus));
|
|
|
e858312 |
+ bus = calloc(1, sizeof(*bus));
|
|
|
e858312 |
if (!bus)
|
|
|
e858312 |
USB_ERROR(-ENOMEM);
|
|
|
e858312 |
|
|
|
e858312 |
- memset((void *)bus, 0, sizeof(*bus));
|
|
|
e858312 |
-
|
|
|
e858312 |
strncpy(bus->dirname, entry->d_name, sizeof(bus->dirname) - 1);
|
|
|
e858312 |
bus->dirname[sizeof(bus->dirname) - 1] = 0;
|
|
|
e858312 |
|
|
|
e858312 |
@@ -367,6 +365,9 @@ int usb_os_find_devices(struct usb_bus *
|
|
|
e858312 |
{
|
|
|
e858312 |
struct usb_device *fdev = NULL;
|
|
|
e858312 |
DIR *dir;
|
|
|
e858312 |
+#ifdef HAVE_OPENAT
|
|
|
e858312 |
+ int dfd;
|
|
|
e858312 |
+#endif
|
|
|
e858312 |
struct dirent *entry;
|
|
|
e858312 |
char dirpath[PATH_MAX + 1];
|
|
|
e858312 |
|
|
|
e858312 |
@@ -376,37 +377,54 @@ int usb_os_find_devices(struct usb_bus *
|
|
|
e858312 |
if (!dir)
|
|
|
e858312 |
USB_ERROR_STR(-errno, "couldn't opendir(%s): %s", dirpath,
|
|
|
e858312 |
strerror(errno));
|
|
|
e858312 |
+#ifdef HAVE_OPENAT
|
|
|
e858312 |
+ dfd = dirfd (dir);
|
|
|
e858312 |
+#endif
|
|
|
e858312 |
|
|
|
e858312 |
while ((entry = readdir(dir)) != NULL) {
|
|
|
e858312 |
unsigned char device_desc[DEVICE_DESC_LENGTH];
|
|
|
e858312 |
+#ifndef HAVE_OPENAT
|
|
|
e858312 |
char filename[PATH_MAX + 1];
|
|
|
e858312 |
+#endif
|
|
|
e858312 |
struct usb_device *dev;
|
|
|
e858312 |
struct usb_connectinfo connectinfo;
|
|
|
e858312 |
int i, fd, ret;
|
|
|
e858312 |
|
|
|
e858312 |
+#ifdef _DIRENT_HAVE_D_TYPE
|
|
|
e858312 |
+ /* If we know this is a directory don't bother any further. */
|
|
|
e858312 |
+ if (entry->d_type == DT_DIR)
|
|
|
e858312 |
+ continue;
|
|
|
e858312 |
+#endif
|
|
|
e858312 |
+
|
|
|
e858312 |
/* Skip anything starting with a . */
|
|
|
e858312 |
if (entry->d_name[0] == '.')
|
|
|
e858312 |
continue;
|
|
|
e858312 |
|
|
|
e858312 |
- dev = malloc(sizeof(*dev));
|
|
|
e858312 |
+ dev = calloc(1, sizeof(*dev));
|
|
|
e858312 |
if (!dev)
|
|
|
e858312 |
USB_ERROR(-ENOMEM);
|
|
|
e858312 |
|
|
|
e858312 |
- memset((void *)dev, 0, sizeof(*dev));
|
|
|
e858312 |
-
|
|
|
e858312 |
dev->bus = bus;
|
|
|
e858312 |
|
|
|
e858312 |
strncpy(dev->filename, entry->d_name, sizeof(dev->filename) - 1);
|
|
|
e858312 |
dev->filename[sizeof(dev->filename) - 1] = 0;
|
|
|
e858312 |
|
|
|
e858312 |
+#ifdef HAVE_OPENAT
|
|
|
e858312 |
+ fd = openat(dfd, entry->d_name, O_RDWR);
|
|
|
e858312 |
+#else
|
|
|
e858312 |
snprintf(filename, sizeof(filename) - 1, "%s/%s", dirpath, entry->d_name);
|
|
|
e858312 |
fd = open(filename, O_RDWR);
|
|
|
e858312 |
+#endif
|
|
|
e858312 |
if (fd < 0) {
|
|
|
e858312 |
+#ifdef HAVE_OPENAT
|
|
|
e858312 |
+ fd = openat(dfd, entry->d_name, O_RDONLY);
|
|
|
e858312 |
+#else
|
|
|
e858312 |
fd = open(filename, O_RDONLY);
|
|
|
e858312 |
+#endif
|
|
|
e858312 |
if (fd < 0) {
|
|
|
e858312 |
if (usb_debug >= 2)
|
|
|
e858312 |
- fprintf(stderr, "usb_os_find_devices: Couldn't open %s\n",
|
|
|
e858312 |
- filename);
|
|
|
e858312 |
+ fprintf(stderr, "usb_os_find_devices: Couldn't open %s/%s\n",
|
|
|
e858312 |
+ dirpath, entry->d_name);
|
|
|
e858312 |
|
|
|
e858312 |
free(dev);
|
|
|
e858312 |
continue;
|
|
|
e858312 |
@@ -453,14 +471,11 @@ int usb_os_find_devices(struct usb_bus *
|
|
|
e858312 |
/* Silent since we'll try again later */
|
|
|
e858312 |
goto err;
|
|
|
e858312 |
|
|
|
e858312 |
- dev->config = (struct usb_config_descriptor *)malloc(dev->descriptor.bNumConfigurations * sizeof(struct usb_config_descriptor));
|
|
|
e858312 |
+ dev->config = (struct usb_config_descriptor *)calloc(dev->descriptor.bNumConfigurations, sizeof(struct usb_config_descriptor));
|
|
|
e858312 |
if (!dev->config)
|
|
|
e858312 |
/* Silent since we'll try again later */
|
|
|
e858312 |
goto err;
|
|
|
e858312 |
|
|
|
e858312 |
- memset(dev->config, 0, dev->descriptor.bNumConfigurations *
|
|
|
e858312 |
- sizeof(struct usb_config_descriptor));
|
|
|
e858312 |
-
|
|
|
e858312 |
for (i = 0; i < dev->descriptor.bNumConfigurations; i++) {
|
|
|
e858312 |
unsigned char buffer[8], *bigbuffer;
|
|
|
e858312 |
struct usb_config_descriptor config;
|