#define UTIL_LINUX_PATH_H
#include <stdio.h>
+#include <stdint.h>
extern FILE *path_fopen(const char *mode, int exit_on_err, const char *path, ...)
__attribute__ ((__format__ (__printf__, 3, 4)));
extern int path_write_str(const char *str, const char *path, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
extern int path_read_s32(const char *path, ...)
- __attribute__ ((__format__ (__printf__, 1, 2)));
+ __attribute__ ((__format__ (__printf__, 1, 2)));
+extern uint64_t path_read_u64(const char *path, ...)
+ __attribute__ ((__format__ (__printf__, 1, 2)));
+
extern int path_exist(const char *path, ...)
__attribute__ ((__format__ (__printf__, 1, 2)));
#include <string.h>
#include <unistd.h>
#include <stdio.h>
+#include <inttypes.h>
#include <errno.h>
#include "all-io.h"
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, ...)
{