]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/path: use _vreadf_buffer for _cpuparse()
authorThomas Weißschuh <thomas@t-8ch.de>
Mon, 13 May 2024 08:46:39 +0000 (10:46 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Mon, 13 May 2024 19:02:34 +0000 (21:02 +0200)
ul_path_vreadf_buffer already provides zero-termination and newline
trimming, so make use of it.

We now could read more than a single line, but the files this is used on
contain only a single line anyways.

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

index 6a70ad45f7d1cfeb180bef8527f01c36bcc6d115..42a33ffc53752ba5e00aed2396ca9a4fc876c1ef 100644 (file)
@@ -1021,7 +1021,6 @@ int ul_path_next_dirent(struct path_cxt *pc, DIR **sub, const char *dirname, str
 #ifdef HAVE_CPU_SET_T
 static int ul_path_cpuparse(struct path_cxt *pc, cpu_set_t **set, int maxcpus, int islist, const char *path, va_list ap)
 {
-       FILE *f;
        size_t setsize, len = maxcpus * 7;
        char *buf;
        int rc;
@@ -1032,27 +1031,10 @@ static int ul_path_cpuparse(struct path_cxt *pc, cpu_set_t **set, int maxcpus, i
        if (!buf)
                return -ENOMEM;
 
-       f = ul_path_vfopenf(pc, "r" UL_CLOEXECSTR, path, ap);
-       if (!f) {
-               rc = -errno;
-               goto out;
-       }
-
-       if (fgets(buf, len, f) == NULL) {
-               errno = EIO;
-               rc = -errno;
-       } else
-               rc = 0;
-
-       fclose(f);
-
-       if (rc)
+       rc = ul_path_vreadf_buffer(pc, buf, len, path, ap);
+       if (rc < 0)
                goto out;
 
-       len = strlen(buf);
-       if (len > 0 && buf[len - 1] == '\n')
-               buf[len - 1] = '\0';
-
        *set = cpuset_alloc(maxcpus, &setsize, NULL);
        if (!*set) {
                rc = -EINVAL;