]> err.no Git - yubikey-personalization/commitdiff
make error handling match that of other ykcore implementations
authorKlas Lindfors <klas@yubico.com>
Mon, 8 Oct 2012 06:48:48 +0000 (07:48 +0100)
committerKlas Lindfors <klas@yubico.com>
Mon, 8 Oct 2012 07:20:55 +0000 (08:20 +0100)
ykcore/ykcore_osx.c

index f3811368610d32a4ce05b7fecf6f641bc7cc34b9..4b3bac3cb5a977ccf66bd2b2b2cc289499f0a29c 100644 (file)
@@ -79,7 +79,7 @@ void *_ykusb_open_device(int vendor_id, int product_id)
        CFStringRef keys[2];
        CFStringRef values[2];
 
-       yk_errno = YK_EUSBERR;
+       int rc = YK_ENOKEY;
 
        CFNumberRef vendorID = CFNumberCreate( kCFAllocatorDefault, kCFNumberIntType, &vendor_id );
        CFNumberRef productID = CFNumberCreate( kCFAllocatorDefault, kCFNumberIntType, &product_id );
@@ -94,6 +94,7 @@ void *_ykusb_open_device(int vendor_id, int product_id)
        CFSetRef devSet = IOHIDManagerCopyDevices( ykosxManager );
 
        if ( devSet ) {
+               rc = YK_EUSBERR;
 
                CFMutableArrayRef array = CFArrayCreateMutable( kCFAllocatorDefault, 0, NULL );
 
@@ -104,8 +105,9 @@ void *_ykusb_open_device(int vendor_id, int product_id)
                if (cnt > 0) {
                        yk = (void *) CFArrayGetValueAtIndex( array, 0 );
                }
-               else
-                       yk_errno = YK_ENOKEY;
+               else {
+                       rc = YK_ENOKEY;
+               }
 
                CFRelease( array );
                CFRelease( devSet );
@@ -120,13 +122,14 @@ void *_ykusb_open_device(int vendor_id, int product_id)
 
                if ( _ykusb_IOReturn != kIOReturnSuccess ) {
                        yk_release();
-                       return 0;
+                       goto error;
                }
 
-               yk_errno = 0;
                return yk;
        }
 
+error:
+       yk_errno = rc;
        return 0;
 }