From: Martin Ling Date: Sat, 23 Nov 2013 11:57:17 +0000 (+0000) Subject: Return SP_ERR_SUPP from sp_list_ports() on unsupported platforms. X-Git-Tag: libserialport-0.1.0~61 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=6b93ede4194fddb0a319fae9cce8bd2e8cea9982;p=libserialport.git Return SP_ERR_SUPP from sp_list_ports() on unsupported platforms. --- diff --git a/README b/README index 35b3243..87de434 100644 --- a/README +++ b/README @@ -25,8 +25,8 @@ The library should build and work on any Windows or Unix-based system. If it does not, please submit a bug. Enumeration is currently only implemented on Windows, Mac OS X and Linux. On -other systems enumeration will return no results, but ports can still be opened -by name and then used. +other systems enumeration is not supported, but ports can still be opened by +name and then used. If you know how to enumerate available ports on another OS, please submit a bug with this information, or better still a patch implementing it. diff --git a/serialport.c b/serialport.c index 05aff3a..4b25eaf 100644 --- a/serialport.c +++ b/serialport.c @@ -246,7 +246,7 @@ fail: enum sp_return sp_list_ports(struct sp_port ***list_ptr) { struct sp_port **list; - int ret = SP_OK; + int ret = SP_ERR_SUPP; TRACE("%p", list_ptr); @@ -269,6 +269,8 @@ enum sp_return sp_list_ports(struct sp_port ***list_ptr) char *name; int name_len; + ret = SP_OK; + DEBUG("Opening registry key"); if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("HARDWARE\\DEVICEMAP\\SERIALCOMM"), 0, KEY_QUERY_VALUE, &key) != ERROR_SUCCESS) { @@ -339,6 +341,8 @@ out_done: CFTypeRef cf_path; Boolean result; + ret = SP_OK; + DEBUG("Getting IOKit master port"); if (IOMasterPort(MACH_PORT_NULL, &master) != KERN_SUCCESS) { SET_FAIL(ret, "IOMasterPort() failed"); @@ -402,6 +406,8 @@ out_done: int fd, ioctl_result; struct serial_struct serial_info; + ret = SP_OK; + DEBUG("Enumerating tty devices"); ud = udev_new(); ud_enumerate = udev_enumerate_new(ud); @@ -456,10 +462,13 @@ out: udev_unref(ud); #endif - if (ret == SP_OK) { + switch (ret) { + case SP_OK: *list_ptr = list; RETURN_OK(); - } else { + case SP_ERR_SUPP: + DEBUG_ERROR(SP_ERR_SUPP, "Enumeration not supported on this platform."); + default: if (list) sp_free_port_list(list); *list_ptr = NULL;