summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarel Zak2018-05-17 15:42:37 +0200
committerKarel Zak2018-06-21 13:07:46 +0200
commit7eb8e47bcd9979689b00625df6e7a20a2b9e2d41 (patch)
tree972c6248c85add66a30e5c0dcc30b99a652ec9dd /lib
parentlib/path: add ul_path_get_abspath() (diff)
downloadkernel-qcow2-util-linux-7eb8e47bcd9979689b00625df6e7a20a2b9e2d41.tar.gz
kernel-qcow2-util-linux-7eb8e47bcd9979689b00625df6e7a20a2b9e2d41.tar.xz
kernel-qcow2-util-linux-7eb8e47bcd9979689b00625df6e7a20a2b9e2d41.zip
lib/path: add ul_path_read_buffer()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/path.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/path.c b/lib/path.c
index 63f19af9a..76b672a7f 100644
--- a/lib/path.c
+++ b/lib/path.c
@@ -565,6 +565,35 @@ int ul_path_readf_string(struct path_cxt *pc, char **str, const char *path, ...)
return ul_path_read_string(pc, str, p);
}
+int ul_path_read_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char *path)
+{
+ int rc = ul_path_read(pc, buf, bufsz - 1, path);
+ if (rc < 0)
+ return rc;;
+
+ /* Remove tailing newline (usuall in sysfs) */
+ if (rc > 0 && *(buf + rc - 1) == '\n')
+ --rc;
+
+ buf[rc] = '\0';
+ return rc;
+}
+
+int ul_path_readf_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, ...)
+{
+ const char *p;
+ va_list ap;
+
+ va_start(ap, path);
+ p = ul_path_mkpath(pc, path, ap);
+ va_end(ap);
+
+ if (!p)
+ return -EINVAL;
+
+ return ul_path_read_buffer(pc, buf, bufsz, p);
+}
+
int ul_path_scanf(struct path_cxt *pc, const char *path, const char *fmt, ...)
{
FILE *f;