linux: Fix type of open() flags argument

The second argument to open() is an int carrying flags (including
"access modes"). A third, optional argument has type mode_t, carrying
"file mode bits" for file permissions.

Also rename the variable to access_mode to make it more clear.

The type mismatch was caught by building with -Wconversion.

References #1497

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
This commit is contained in:
Tormod Volden 2024-05-12 16:13:59 +02:00
parent b00332d34e
commit 8b507434fa
2 changed files with 5 additions and 5 deletions

View file

@ -182,7 +182,7 @@ static int dev_has_config0(struct libusb_device *dev)
return 0;
}
static int get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent)
static int get_usbfs_fd(struct libusb_device *dev, int access_mode, int silent)
{
struct libusb_context *ctx = DEVICE_CTX(dev);
char path[24];
@ -195,7 +195,7 @@ static int get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent)
snprintf(path, sizeof(path), USB_DEVTMPFS_PATH "/%03u/%03u",
dev->bus_number, dev->device_address);
fd = open(path, mode | O_CLOEXEC);
fd = open(path, access_mode | O_CLOEXEC);
if (fd != -1)
return fd; /* Success */
@ -209,14 +209,14 @@ static int get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent)
/* Wait 10ms for USB device path creation.*/
nanosleep(&delay_ts, NULL);
fd = open(path, mode | O_CLOEXEC);
fd = open(path, access_mode | O_CLOEXEC);
if (fd != -1)
return fd; /* Success */
}
if (!silent) {
usbi_err(ctx, "libusb couldn't open USB device %s, errno=%d", path, errno);
if (errno == EACCES && mode == O_RDWR)
if (errno == EACCES && access_mode == O_RDWR)
usbi_err(ctx, "libusb requires write access to USB device nodes");
}

View file

@ -1 +1 @@
#define LIBUSB_NANO 11900
#define LIBUSB_NANO 11901