X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=linux.c;h=9ccd3b384608d8ed4fd62551a4744f9af04cc5bb;hb=8eb18f7b5a459cde640f307ce46248851fdaec42;hp=730ba9d0433caa2d2b79f089ce236fc8fd2e856a;hpb=48a4076f692ffe34026c37815580a32b2f70592b;p=libserialport.git diff --git a/linux.c b/linux.c index 730ba9d..9ccd3b3 100644 --- a/linux.c +++ b/linux.c @@ -20,7 +20,7 @@ #include "libserialport.h" #include "libserialport_internal.h" -enum sp_return get_port_details(struct sp_port *port) +SP_PRIV enum sp_return get_port_details(struct sp_port *port) { /* Description limited to 127 char, anything longer would not be user friendly anyway */ @@ -156,12 +156,18 @@ enum sp_return get_port_details(struct sp_port *port) RETURN_OK(); } -enum sp_return list_ports(struct sp_port ***list) +SP_PRIV enum sp_return list_ports(struct sp_port ***list) { char name[PATH_MAX], target[PATH_MAX]; struct dirent entry, *result; +#ifdef HAVE_SERIAL_STRUCT struct serial_struct serial_info; - int len, fd, ioctl_result; + int ioctl_result; +#endif +#ifndef HAVE_READLINKAT + char buf[sizeof(entry.d_name) + 16]; +#endif + int len, fd; DIR *dir; int ret = SP_OK; @@ -171,7 +177,12 @@ enum sp_return list_ports(struct sp_port ***list) DEBUG("Iterating over results"); while (!readdir_r(dir, &entry, &result) && result) { +#ifdef HAVE_READLINKAT len = readlinkat(dirfd(dir), entry.d_name, target, sizeof(target)); +#else + snprintf(buf, sizeof(buf), "/sys/class/tty/%s", entry.d_name); + len = readlink(buf, target, sizeof(target)); +#endif if (len <= 0 || len >= (int) sizeof(target)-1) continue; target[len] = 0; @@ -188,8 +199,11 @@ enum sp_return list_ports(struct sp_port ***list) DEBUG("open failed, skipping"); continue; } +#ifdef HAVE_SERIAL_STRUCT ioctl_result = ioctl(fd, TIOCGSERIAL, &serial_info); +#endif close(fd); +#ifdef HAVE_SERIAL_STRUCT if (ioctl_result != 0) { DEBUG("ioctl failed, skipping"); continue; @@ -198,6 +212,7 @@ enum sp_return list_ports(struct sp_port ***list) DEBUG("port type is unknown, skipping"); continue; } +#endif } DEBUG("Found port %s", name); *list = list_append(*list, name);