diff options
author | Karel Zak | 2018-05-17 13:58:30 +0200 |
---|---|---|
committer | Karel Zak | 2018-06-21 13:07:46 +0200 |
commit | e74e5401e11dde927042fa00a6db02d0381e0e0c (patch) | |
tree | 7d3898b3ffebad338ce8c78211c6c984a2e43079 /lib | |
parent | zramctl: use new ul_path_* API (diff) | |
download | kernel-qcow2-util-linux-e74e5401e11dde927042fa00a6db02d0381e0e0c.tar.gz kernel-qcow2-util-linux-e74e5401e11dde927042fa00a6db02d0381e0e0c.tar.xz kernel-qcow2-util-linux-e74e5401e11dde927042fa00a6db02d0381e0e0c.zip |
lib/path: add ul_path_get_abspath()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/path.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/lib/path.c b/lib/path.c index b1d0be9d1..63f19af9a 100644 --- a/lib/path.c +++ b/lib/path.c @@ -176,7 +176,6 @@ static const char *get_absdir(struct path_cxt *pc) return pc->path_buffer; } - int ul_path_get_dirfd(struct path_cxt *pc) { assert(pc); @@ -209,6 +208,39 @@ static const char *ul_path_mkpath(struct path_cxt *pc, const char *path, va_list return pc->path_buffer; } +char *ul_path_get_abspath(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, ...) +{ + if (path) { + int rc; + va_list ap; + const char *tail = NULL; + + va_start(ap, path); + tail = ul_path_mkpath(pc, path, ap); + va_end(ap); + + rc = snprintf(buf, bufsz, "%s/%s/%s", + pc->prefix ? pc->prefix : "", + pc->dir_path, + tail); + + if ((size_t)rc >= bufsz) { + errno = ENAMETOOLONG; + return NULL; + } + } else { + const char *tmp = get_absdir(pc); + + if (!tmp) + return NULL; + strncpy(buf, tmp, bufsz); + buf[bufsz - 1] = '\0'; + } + + return buf; +} + + int ul_path_access(struct path_cxt *pc, int mode, const char *path) { int dir, rc; |