Skip to content

Commit

Permalink
libusb0: Rename nut API functions for consistency with libusb1.c
Browse files Browse the repository at this point in the history
The original names could also be confused with libusb-1.0 API
functions.

Also rename nut_libusb_strerror() although not a nut API function.

Signed-off-by: Tormod Volden <[email protected]>
  • Loading branch information
tormodvolden committed Aug 28, 2024
1 parent 03c1ea7 commit 91fd69d
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions drivers/libusb0.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ upsdrv_info_t comm_upsdrv_info = {
static char *strcasestr(const char *haystack, const char *needle);
#endif

static void libusb_close(usb_dev_handle *udev);
static void nut_libusb_close(usb_dev_handle *udev);

/*! Add USB-related driver variables with addvar() and dstate_setinfo().
* This removes some code duplication across the USB drivers.
Expand Down Expand Up @@ -196,7 +196,7 @@ static int nut_usb_set_altinterface(usb_dev_handle *udev)
* is accepted, or < 1 if not. If it isn't accepted, the next device
* (if any) will be tried, until there are no more devices left.
*/
static int libusb_open(usb_dev_handle **udevp,
static int nut_libusb_open(usb_dev_handle **udevp,
USBDevice_t *curDevice, USBDeviceMatcher_t *matcher,
int (*callback)(usb_dev_handle *udev,
USBDevice_t *hd, usb_ctrl_charbuf rdbuf, usb_ctrl_charbufsize rdlen)
Expand Down Expand Up @@ -314,7 +314,7 @@ static int libusb_open(usb_dev_handle **udevp,

#ifndef __linux__ /* SUN_LIBUSB (confirmed to work on Solaris and FreeBSD) */
/* Causes a double free corruption in linux if device is detached! */
libusb_close(*udevp);
nut_libusb_close(*udevp);
#endif

upsdebugx(3, "usb_busses=%p", (void*)usb_busses);
Expand Down Expand Up @@ -733,7 +733,7 @@ static int libusb_open(usb_dev_handle **udevp,
* Error handler for usb_get/set_* functions. Return value > 0 success,
* 0 unknown or temporary failure (ignored), < 0 permanent failure (reconnect)
*/
static int libusb_strerror(const int ret, const char *desc)
static int nut_libusb_strerror(const int ret, const char *desc)
{
if (ret > 0) {
return ret;
Expand Down Expand Up @@ -780,18 +780,18 @@ static int libusb_strerror(const int ret, const char *desc)
*/

/* Expected evaluated types for the API:
* static int libusb_get_report(usb_dev_handle *udev,
* static int nut_libusb_get_report(usb_dev_handle *udev,
* int ReportId, unsigned char *raw_buf, int ReportSize)
*/
static int libusb_get_report(
static int nut_libusb_get_report(
usb_dev_handle *udev,
usb_ctrl_repindex ReportId,
usb_ctrl_charbuf raw_buf,
usb_ctrl_charbufsize ReportSize)
{
int ret;

upsdebugx(4, "Entering libusb_get_report");
upsdebugx(4, "Entering nut_libusb_get_report");

if (!udev) {
return 0;
Expand All @@ -813,14 +813,14 @@ static int libusb_get_report(
return 0;
}

return libusb_strerror(ret, __func__);
return nut_libusb_strerror(ret, __func__);
}

/* Expected evaluated types for the API:
* static int libusb_set_report(usb_dev_handle *udev,
* static int nut_libusb_set_report(usb_dev_handle *udev,
* int ReportId, unsigned char *raw_buf, int ReportSize)
*/
static int libusb_set_report(
static int nut_libusb_set_report(
usb_dev_handle *udev,
usb_ctrl_repindex ReportId,
usb_ctrl_charbuf raw_buf,
Expand Down Expand Up @@ -848,14 +848,14 @@ static int libusb_set_report(
return 0;
}

return libusb_strerror(ret, __func__);
return nut_libusb_strerror(ret, __func__);
}

/* Expected evaluated types for the API:
* static int libusb_get_string(usb_dev_handle *udev,
* static int nut_libusb_get_string(usb_dev_handle *udev,
* int StringIdx, char *buf, int buflen)
*/
static int libusb_get_string(
static int nut_libusb_get_string(
usb_dev_handle *udev,
usb_ctrl_strindex StringIdx,
char *buf,
Expand Down Expand Up @@ -889,17 +889,17 @@ static int libusb_get_string(
"actual buf length is %" PRIuSIZE, __func__, len);
/* if (len) */
return len;
/* else may log "libusb_get_string: Success" and return 0 below */
/* else may log "nut_libusb_get_string: Success" and return 0 below */
}

return libusb_strerror(ret, __func__);
return nut_libusb_strerror(ret, __func__);
}

/* Expected evaluated types for the API:
* static int libusb_get_interrupt(usb_dev_handle *udev,
* static int nut_libusb_get_interrupt(usb_dev_handle *udev,
* unsigned char *buf, int bufsize, int timeout)
*/
static int libusb_get_interrupt(
static int nut_libusb_get_interrupt(
usb_dev_handle *udev,
usb_ctrl_charbuf buf,
usb_ctrl_charbufsize bufsize,
Expand All @@ -923,10 +923,10 @@ static int libusb_get_interrupt(
ret = usb_clear_halt(udev, 0x81);
}

return libusb_strerror(ret, __func__);
return nut_libusb_strerror(ret, __func__);
}

static void libusb_close(usb_dev_handle *udev)
static void nut_libusb_close(usb_dev_handle *udev)
{
if (!udev) {
return;
Expand Down Expand Up @@ -973,12 +973,12 @@ static char *strcasestr(const char *haystack, const char *needle) {
usb_communication_subdriver_t usb_subdriver = {
USB_DRIVER_NAME,
USB_DRIVER_VERSION,
libusb_open,
libusb_close,
libusb_get_report,
libusb_set_report,
libusb_get_string,
libusb_get_interrupt,
nut_libusb_open,
nut_libusb_close,
nut_libusb_get_report,
nut_libusb_set_report,
nut_libusb_get_string,
nut_libusb_get_interrupt,
LIBUSB_DEFAULT_CONF_INDEX,
LIBUSB_DEFAULT_INTERFACE,
LIBUSB_DEFAULT_DESC_INDEX,
Expand Down

0 comments on commit 91fd69d

Please sign in to comment.