1
0
mirror of git://sigrok.org/libserialport synced 2023-08-10 21:13:24 +03:00

Return SP_ERR_SUPP from sp_list_ports() on unsupported platforms.

This commit is contained in:
Martin Ling 2013-11-23 11:57:17 +00:00
parent 64690702cb
commit 6b93ede419
2 changed files with 14 additions and 5 deletions

4
README
View File

@ -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. does not, please submit a bug.
Enumeration is currently only implemented on Windows, Mac OS X and Linux. On 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 other systems enumeration is not supported, but ports can still be opened by
by name and then used. name and then used.
If you know how to enumerate available ports on another OS, please submit a bug 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. with this information, or better still a patch implementing it.

View File

@ -246,7 +246,7 @@ fail:
enum sp_return sp_list_ports(struct sp_port ***list_ptr) enum sp_return sp_list_ports(struct sp_port ***list_ptr)
{ {
struct sp_port **list; struct sp_port **list;
int ret = SP_OK; int ret = SP_ERR_SUPP;
TRACE("%p", list_ptr); TRACE("%p", list_ptr);
@ -269,6 +269,8 @@ enum sp_return sp_list_ports(struct sp_port ***list_ptr)
char *name; char *name;
int name_len; int name_len;
ret = SP_OK;
DEBUG("Opening registry key"); DEBUG("Opening registry key");
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("HARDWARE\\DEVICEMAP\\SERIALCOMM"), if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("HARDWARE\\DEVICEMAP\\SERIALCOMM"),
0, KEY_QUERY_VALUE, &key) != ERROR_SUCCESS) { 0, KEY_QUERY_VALUE, &key) != ERROR_SUCCESS) {
@ -339,6 +341,8 @@ out_done:
CFTypeRef cf_path; CFTypeRef cf_path;
Boolean result; Boolean result;
ret = SP_OK;
DEBUG("Getting IOKit master port"); DEBUG("Getting IOKit master port");
if (IOMasterPort(MACH_PORT_NULL, &master) != KERN_SUCCESS) { if (IOMasterPort(MACH_PORT_NULL, &master) != KERN_SUCCESS) {
SET_FAIL(ret, "IOMasterPort() failed"); SET_FAIL(ret, "IOMasterPort() failed");
@ -402,6 +406,8 @@ out_done:
int fd, ioctl_result; int fd, ioctl_result;
struct serial_struct serial_info; struct serial_struct serial_info;
ret = SP_OK;
DEBUG("Enumerating tty devices"); DEBUG("Enumerating tty devices");
ud = udev_new(); ud = udev_new();
ud_enumerate = udev_enumerate_new(ud); ud_enumerate = udev_enumerate_new(ud);
@ -456,10 +462,13 @@ out:
udev_unref(ud); udev_unref(ud);
#endif #endif
if (ret == SP_OK) { switch (ret) {
case SP_OK:
*list_ptr = list; *list_ptr = list;
RETURN_OK(); RETURN_OK();
} else { case SP_ERR_SUPP:
DEBUG_ERROR(SP_ERR_SUPP, "Enumeration not supported on this platform.");
default:
if (list) if (list)
sp_free_port_list(list); sp_free_port_list(list);
*list_ptr = NULL; *list_ptr = NULL;