]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/path: use _read_buffer for _read_string()
authorThomas Weißschuh <thomas@t-8ch.de>
Mon, 13 May 2024 08:46:31 +0000 (10:46 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Mon, 13 May 2024 10:35:48 +0000 (12:35 +0200)
ul_path_read_buffer already provides zero-termination and newline
trimming, so make use of it.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
lib/path.c

index 7a1d03c76d07ac72b2a91ca0a3e2e80ca0abe9a9..6381cc5d8fa35c7c1ee8acdf6023e6e6f0645743 100644 (file)
@@ -659,17 +659,11 @@ int ul_path_read_string(struct path_cxt *pc, char **str, const char *path)
                return -EINVAL;
 
        *str = NULL;
-       rc = ul_path_read(pc, buf, sizeof(buf) - 1, path);
+
+       rc = ul_path_read_buffer(pc, buf, sizeof(buf), path);
        if (rc < 0)
                return rc;
 
-       /* Remove trailing newline (usual in sysfs) */
-       if (rc > 0 && *(buf + rc - 1) == '\n')
-               --rc;
-       if (rc == 0)
-               return 0;
-
-       buf[rc] = '\0';
        *str = strdup(buf);
        if (!*str)
                rc = -ENOMEM;