X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=linux.c;h=8e9bfbf72ccbd1c46e4d0511020eb9f0f11421ed;hb=7c1101dc083533c36df135e78f8e9174b4caf08d;hp=dbff4c4459282a376e2035c6e3f005474939d9a4;hpb=7890cef6cf4f8496888f2a86593f9eff55244456;p=libserialport.git diff --git a/linux.c b/linux.c index dbff4c4..8e9bfbf 100644 --- a/linux.c +++ b/linux.c @@ -25,7 +25,8 @@ 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 */ char description[128]; - int bus, address, vid, pid = -1; + int bus, address; + unsigned int vid, pid; char manufacturer[128], product[128], serial[128]; char baddr[32]; const char dir_name[] = "/sys/class/tty/%s/device/%s%s"; @@ -134,6 +135,15 @@ SP_PRIV enum sp_return get_port_details(struct sp_port *port) fclose(file); } + /* If present, add serial to description for better identification. */ + if (port->usb_serial && strlen(port->usb_serial)) { + snprintf(description, sizeof(description), + "%s - %s", port->description, port->usb_serial); + if (port->description) + free(port->description); + port->description = strdup(description); + } + break; } } else { @@ -164,9 +174,7 @@ SP_PRIV enum sp_return list_ports(struct sp_port ***list) struct serial_struct serial_info; int ioctl_result; #endif -#ifndef HAVE_READLINKAT char buf[sizeof(entry.d_name) + 16]; -#endif int len, fd; DIR *dir; int ret = SP_OK; @@ -177,12 +185,8 @@ SP_PRIV 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;