diff options
author | Karel Zak | 2012-11-05 12:28:00 +0100 |
---|---|---|
committer | Karel Zak | 2012-11-23 14:58:21 +0100 |
commit | 37a5c7ee418d9684e3e444934b98a7474a898b3b (patch) | |
tree | 120b14eec65db50503e567fd4039e4d4b91202e4 /lib/path.c | |
parent | lib/path: rename functions to be more explicit (diff) | |
download | kernel-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.c | 22 |
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, ...) { |