From: Thomas Weißschuh Date: Mon, 13 May 2024 08:46:39 +0000 (+0200) Subject: lib/path: use _vreadf_buffer for _cpuparse() X-Git-Tag: v2.42-start~343 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=961dfad332144d13e36a15132bc5d625b212a5de;p=thirdparty%2Futil-linux.git lib/path: use _vreadf_buffer for _cpuparse() 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 --- diff --git a/lib/path.c b/lib/path.c index 6a70ad45f..42a33ffc5 100644 --- a/lib/path.c +++ b/lib/path.c @@ -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;