From: Klas Lindfors Date: Fri, 10 Jan 2014 09:53:12 +0000 (+0100) Subject: add a new error: YK_ENODATA X-Git-Tag: v1.15.0~3 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=11ff22750b16d0021313d494738a8de6033400d2;p=yubikey-personalization add a new error: YK_ENODATA used when read from device returns no data but no underlying error --- diff --git a/ykcore/ykcore.c b/ykcore/ykcore.c index a4f0b04..31a9460 100644 --- a/ykcore/ykcore.c +++ b/ykcore/ykcore.c @@ -403,6 +403,7 @@ static const char *errtext[] = { "operation would block", "invalid command for operation", "expected only one YubiKey but several present", + "no data returned from device", }; const char *yk_strerror(int errnum) { diff --git a/ykcore/ykcore.h b/ykcore/ykcore.h index 8d032a5..33d0592 100644 --- a/ykcore/ykcore.h +++ b/ykcore/ykcore.h @@ -160,6 +160,7 @@ const char *yk_usb_strerror(void); #define YK_EWOULDBLOCK 0x0b /* operation would block */ #define YK_EINVALIDCMD 0x0c /* supplied command is invalid for this operation */ #define YK_EMORETHANONE 0x0d /* expected to find only one key but found more */ +#define YK_ENODATA 0x0e /* no data was returned from a read */ /* Flags for response reading. Use high numbers to not exclude the possibility * to combine these with for example SLOT commands from ykdef.h in the future. diff --git a/ykcore/ykcore_libusb-1.0.c b/ykcore/ykcore_libusb-1.0.c index a3541c1..2385e7f 100644 --- a/ykcore/ykcore_libusb-1.0.c +++ b/ykcore/ykcore_libusb-1.0.c @@ -128,9 +128,13 @@ int _ykusb_read(void *dev, int report_type, int report_number, if (ykl_errno > 0 && rc2 < 0) ykl_errno = rc2; } - if (ykl_errno > 0) + if (ykl_errno > 0) { return ykl_errno; - yk_errno = YK_EUSBERR; + } else if(ykl_errno == 0) { + yk_errno = YK_ENODATA; + } else { + yk_errno = YK_EUSBERR; + } return 0; } diff --git a/ykcore/ykcore_libusb.c b/ykcore/ykcore_libusb.c index 35cd680..1c9c116 100644 --- a/ykcore/ykcore_libusb.c +++ b/ykcore/ykcore_libusb.c @@ -121,7 +121,10 @@ int _ykusb_read(void *dev, int report_type, int report_number, } if (rc >= 0) return rc; - yk_errno = YK_EUSBERR; + if(rc == 0) + yk_errno = YK_ENODATA; + else + yk_errno = YK_EUSBERR; return 0; } diff --git a/ykcore/ykcore_osx.c b/ykcore/ykcore_osx.c index bd4538a..b9f2087 100644 --- a/ykcore/ykcore_osx.c +++ b/ykcore/ykcore_osx.c @@ -185,6 +185,9 @@ int _ykusb_read(void *dev, int report_type, int report_number, return 0; } + if(sizecf == 0) + yk_errno = YK_ENODATA; + return (int)sizecf; }