]> sigrok.org Git - libserialport.git/commitdiff
linux: Fix compile warning on gcc 6+ for readlink() call.
authorMartin Ling <redacted>
Tue, 31 Dec 2019 15:50:55 +0000 (16:50 +0100)
committerUwe Hermann <redacted>
Sat, 4 Jan 2020 17:24:00 +0000 (18:24 +0100)
Fixes #1268.

linux.c

diff --git a/linux.c b/linux.c
index 0f1367f0ed5356c7861c8e4d664c59efe0185cc2..8f320859dc91b329caf6688a3e250ad371b6a5d5 100644 (file)
--- a/linux.c
+++ b/linux.c
@@ -46,7 +46,7 @@ SP_PRIV enum sp_return get_port_details(struct sp_port *port)
        char manufacturer[128], product[128], serial[128];
        char baddr[32];
        const char dir_name[] = "/sys/class/tty/%s/device/%s%s";
-       char sub_dir[32] = "", file_name[PATH_MAX];
+       char sub_dir[32] = "", link_name[PATH_MAX], file_name[PATH_MAX];
        char *ptr, *dev = port->name + 5;
        FILE *file;
        int i, count;
@@ -55,12 +55,12 @@ SP_PRIV enum sp_return get_port_details(struct sp_port *port)
        if (strncmp(port->name, "/dev/", 5))
                RETURN_ERROR(SP_ERR_ARG, "Device name not recognized");
 
-       snprintf(file_name, sizeof(file_name), "/sys/class/tty/%s", dev);
-       if (lstat(file_name, &statbuf) == -1)
+       snprintf(link_name, sizeof(link_name), "/sys/class/tty/%s", dev);
+       if (lstat(link_name, &statbuf) == -1)
                RETURN_ERROR(SP_ERR_ARG, "Device not found");
        if (!S_ISLNK(statbuf.st_mode))
-               snprintf(file_name, sizeof(file_name), "/sys/class/tty/%s/device", dev);
-       count = readlink(file_name, file_name, sizeof(file_name));
+               snprintf(link_name, sizeof(link_name), "/sys/class/tty/%s/device", dev);
+       count = readlink(link_name, file_name, sizeof(file_name));
        if (count <= 0 || count >= (int)(sizeof(file_name) - 1))
                RETURN_ERROR(SP_ERR_ARG, "Device not found");
        file_name[count] = 0;