From 37a5c7ee418d9684e3e444934b98a7474a898b3b Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 5 Nov 2012 12:28:00 +0100 Subject: lib/path: add path_read_u64() Signed-off-by: Karel Zak --- lib/path.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lib/path.c') 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 #include #include +#include #include #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, ...) { -- cgit v1.2.3-55-g7522