From 8e58a3f11da4f5ed6c0c149489ff149496d63168 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Sun, 8 Oct 2023 20:49:31 +0200 Subject: [PATCH] lib/path: remove ul_prefix_fopen The function ul_prefix_fopen does not properly check for paths which are too long. Since the only caller of ul_prefix_fopen can be easily converted to ul_path_fopen, remove the function. Signed-off-by: Tobias Stoeckmann --- include/path.h | 2 -- lib/path.c | 19 ------------------- sys-utils/lscpu-virt.c | 2 +- 3 files changed, 1 insertion(+), 22 deletions(-) diff --git a/include/path.h b/include/path.h index 19c1be6e7e..e523f17812 100644 --- a/include/path.h +++ b/include/path.h @@ -134,8 +134,6 @@ int ul_path_countf_dirents(struct path_cxt *pc, const char *path, ...) int ul_path_next_dirent(struct path_cxt *pc, DIR **sub, const char *dirname, struct dirent **d); -FILE *ul_prefix_fopen(const char *prefix, const char *path, const char *mode); - #ifdef HAVE_CPU_SET_T # include "cpuset.h" diff --git a/lib/path.c b/lib/path.c index 9232755ae2..1e4f36a56e 100644 --- a/lib/path.c +++ b/lib/path.c @@ -996,25 +996,6 @@ int ul_path_next_dirent(struct path_cxt *pc, DIR **sub, const char *dirname, str return 1; } -/* - * Like fopen() but, @path is always prefixed by @prefix. This function is - * useful in case when ul_path_* API is overkill. - */ -FILE *ul_prefix_fopen(const char *prefix, const char *path, const char *mode) -{ - char buf[PATH_MAX]; - - if (!path) - return NULL; - if (!prefix) - return fopen(path, mode); - if (*path == '/') - path++; - - snprintf(buf, sizeof(buf), "%s/%s", prefix, path); - return fopen(buf, mode); -} - #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) { diff --git a/sys-utils/lscpu-virt.c b/sys-utils/lscpu-virt.c index 6b6deb8e81..280c462aab 100644 --- a/sys-utils/lscpu-virt.c +++ b/sys-utils/lscpu-virt.c @@ -551,7 +551,7 @@ struct lscpu_virt *lscpu_read_virtualization(struct lscpu_cxt *cxt) if (virt->vendor == VIRT_VENDOR_XEN) { uint32_t features; - fd = ul_prefix_fopen(cxt->prefix, "r", _PATH_SYS_HYP_FEATURES); + fd = ul_path_fopen(cxt->rootfs, "r", _PATH_SYS_HYP_FEATURES); if (fd && fscanf(fd, "%x", &features) == 1) { /* Xen PV domain */ -- 2.47.2