diff options
author | Karel Zak | 2018-05-24 14:06:11 +0200 |
---|---|---|
committer | Karel Zak | 2018-06-21 13:07:46 +0200 |
commit | c87b53ca5fe9fa01fe56890e550e99f7a41f070a (patch) | |
tree | 452ecaebb06efff442fe9fb39a3f88ae92532665 /lib/path.c | |
parent | ipcs: use new ul_path_* API (diff) | |
download | kernel-qcow2-util-linux-c87b53ca5fe9fa01fe56890e550e99f7a41f070a.tar.gz kernel-qcow2-util-linux-c87b53ca5fe9fa01fe56890e550e99f7a41f070a.tar.xz kernel-qcow2-util-linux-c87b53ca5fe9fa01fe56890e550e99f7a41f070a.zip |
lib/path: don't use extra '/'
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/path.c')
-rw-r--r-- | lib/path.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/path.c b/lib/path.c index 11cab3aaf..98455accf 100644 --- a/lib/path.c +++ b/lib/path.c @@ -167,11 +167,18 @@ int ul_path_set_enoent_redirect(struct path_cxt *pc, int (*func)(struct path_cxt static const char *get_absdir(struct path_cxt *pc) { int rc; + const char *dirpath; if (!pc->prefix) return pc->dir_path; - rc = snprintf(pc->path_buffer, sizeof(pc->path_buffer), "%s/%s", pc->prefix, pc->dir_path); + dirpath = pc->dir_path; + if (!dirpath) + return pc->prefix; + if (*dirpath == '/') + dirpath++; + + rc = snprintf(pc->path_buffer, sizeof(pc->path_buffer), "%s/%s", pc->prefix, dirpath); if (rc < 0) return NULL; if ((size_t)rc >= sizeof(pc->path_buffer)) { @@ -219,16 +226,21 @@ char *ul_path_get_abspath(struct path_cxt *pc, char *buf, size_t bufsz, const ch if (path) { int rc; va_list ap; - const char *tail = NULL; + const char *tail = NULL, *dirpath = pc->dir_path; va_start(ap, path); tail = ul_path_mkpath(pc, path, ap); va_end(ap); + if (dirpath && *dirpath == '/') + dirpath++; + if (tail && *tail == '/') + tail++; + rc = snprintf(buf, bufsz, "%s/%s/%s", pc->prefix ? pc->prefix : "", - pc->dir_path, - tail); + dirpath ? dirpath : "", + tail ? tail : ""); if ((size_t)rc >= bufsz) { errno = ENAMETOOLONG; |