summaryrefslogtreecommitdiffstats
path: root/lib/path.c
diff options
context:
space:
mode:
authorKarel Zak2012-11-05 12:28:00 +0100
committerKarel Zak2012-11-23 14:58:21 +0100
commit37a5c7ee418d9684e3e444934b98a7474a898b3b (patch)
tree120b14eec65db50503e567fd4039e4d4b91202e4 /lib/path.c
parentlib/path: rename functions to be more explicit (diff)
downloadkernel-qcow2-util-linux-37a5c7ee418d9684e3e444934b98a7474a898b3b.tar.gz
kernel-qcow2-util-linux-37a5c7ee418d9684e3e444934b98a7474a898b3b.tar.xz
kernel-qcow2-util-linux-37a5c7ee418d9684e3e444934b98a7474a898b3b.zip
lib/path: add path_read_u64()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/path.c')
-rw-r--r--lib/path.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/path.c b/lib/path.c
index f4118ccd3..4f955d91c 100644
--- a/lib/path.c
+++ b/lib/path.c
@@ -27,6 +27,7 @@
#include <string.h>
#include <unistd.h>
#include <stdio.h>
+#include <inttypes.h>
#include <errno.h>
#include "all-io.h"
@@ -125,6 +126,27 @@ path_read_s32(const char *path, ...)
return result;
}
+uint64_t
+path_read_u64(const char *path, ...)
+{
+ FILE *fd;
+ va_list ap;
+ uint64_t result;
+
+ va_start(ap, path);
+ fd = path_vfopen("r", 1, path, ap);
+ va_end(ap);
+
+ if (fscanf(fd, "%"SCNu64, &result) != 1) {
+ if (ferror(fd))
+ err(EXIT_FAILURE, _("failed to read: %s"), pathbuf);
+ else
+ errx(EXIT_FAILURE, _("parse error: %s"), pathbuf);
+ }
+ fclose(fd);
+ return result;
+}
+
int
path_write_str(const char *str, const char *path, ...)
{