]> sigrok.org Git - libserialport.git/blobdiff - serialport.c
Canonicalize symlinks in portnames
[libserialport.git] / serialport.c
index d271478250f8588e0bfe03651b25f492a3d8523e..db2aa43ca0ba98442b042b80ce99e85eb034064c 100644 (file)
@@ -75,6 +75,20 @@ SP_API enum sp_return sp_get_port_by_name(const char *portname, struct sp_port *
 
        DEBUG_FMT("Building structure for port %s", portname);
 
+#if !defined(_WIN32) && defined(HAVE_REALPATH)
+       /*
+        * get_port_details() below tries to be too smart and figure out
+        * some transport properties from the port name which breaks with
+        * symlinks. Therefore we canonicalize the portname first.
+        */
+       char pathbuf[PATH_MAX + 1];
+       char *res = realpath(portname, pathbuf);
+       if (!res)
+               RETURN_ERROR(SP_ERR_ARG, "Could not retrieve realpath behind port name");
+
+       portname = pathbuf;
+#endif
+
        if (!(port = malloc(sizeof(struct sp_port))))
                RETURN_ERROR(SP_ERR_MEM, "Port structure malloc failed");