]> sigrok.org Git - libserialport.git/blobdiff - linux.c
libserialport_internal.h: Add #include guard.
[libserialport.git] / linux.c
diff --git a/linux.c b/linux.c
index dbff4c4459282a376e2035c6e3f005474939d9a4..8e9bfbf72ccbd1c46e4d0511020eb9f0f11421ed 100644 (file)
--- 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;