diff options
author | Chris Dickens <christopher.a.dickens@gmail.com> | 2020-03-16 01:06:27 -0700 |
---|---|---|
committer | Chris Dickens <christopher.a.dickens@gmail.com> | 2020-03-16 01:06:27 -0700 |
commit | 89d574b87976ef58b6c94c26864dcc5330b0c067 (patch) | |
tree | afbd36df0996cfe1294869a3edb0d0521a4ece57 /libusb/os | |
parent | 15bd82e9a2935fd4e5c1a9ed83c73d364e92d8ec (diff) | |
download | libusb-89d574b87976ef58b6c94c26864dcc5330b0c067.tar.gz |
core: Fix return value of usbi_clock_gettime()
In most cases, usbi_clock_gettime() will map to the standard library's
clock_gettime() function. The semantics of this function are that it
returns -1 upon failure with the error code available in the errno
variable. The backends that need to implement this function should
follow the same semantics, and the return value of usbi_clock_gettime()
should not be directly propagated upwards.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Diffstat (limited to 'libusb/os')
-rw-r--r-- | libusb/os/darwin_usb.c | 5 | ||||
-rw-r--r-- | libusb/os/windows_common.c | 14 |
2 files changed, 12 insertions, 7 deletions
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c index e0a364e..f8da747 100644 --- a/libusb/os/darwin_usb.c +++ b/libusb/os/darwin_usb.c @@ -2182,7 +2182,8 @@ int usbi_clock_gettime(int clk_id, struct timespec *tp) { clock_ref = clock_monotonic; break; default: - return LIBUSB_ERROR_INVALID_PARAM; + errno = EINVAL; + return -1; } clock_get_time (clock_ref, &sys_time); @@ -2190,7 +2191,7 @@ int usbi_clock_gettime(int clk_id, struct timespec *tp) { tp->tv_sec = sys_time.tv_sec; tp->tv_nsec = sys_time.tv_nsec; - return LIBUSB_SUCCESS; + return 0; } #endif diff --git a/libusb/os/windows_common.c b/libusb/os/windows_common.c index e37a514..debff74 100644 --- a/libusb/os/windows_common.c +++ b/libusb/os/windows_common.c @@ -24,6 +24,7 @@ #include <config.h> +#include <errno.h> #include <inttypes.h> #include <process.h> #include <stdio.h> @@ -829,13 +830,15 @@ int usbi_clock_gettime(int clk_id, struct timespec *tp) QueryPerformanceCounter(&hires_counter); tp->tv_sec = (long)(hires_counter.QuadPart / hires_frequency); tp->tv_nsec = (long)(((hires_counter.QuadPart % hires_frequency) * hires_ticks_to_ps) / UINT64_C(1000)); - return LIBUSB_SUCCESS; + return 0; } // Fall through and return real-time if monotonic was not detected @ timer init case USBI_CLOCK_REALTIME: #if defined(_MSC_VER) && (_MSC_VER >= 1900) - if (!timespec_get(tp, TIME_UTC)) - return LIBUSB_ERROR_OTHER; + if (!timespec_get(tp, TIME_UTC)) { + errno = EIO; + return -1; + } #else // We follow http://msdn.microsoft.com/en-us/library/ms724928%28VS.85%29.aspx // with a predef epoch time to have an epoch that starts at 1970.01.01 00:00 @@ -848,9 +851,10 @@ int usbi_clock_gettime(int clk_id, struct timespec *tp) tp->tv_sec = (long)(rtime.QuadPart / 10000000); tp->tv_nsec = (long)((rtime.QuadPart % 10000000) * 100); #endif - return LIBUSB_SUCCESS; + return 0; default: - return LIBUSB_ERROR_INVALID_PARAM; + errno = EINVAL; + return -1; } } #endif |