Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
#############################################################################*/
#include <errno.h>
+#include <stdint.h>
#include <stdio.h>
#include "util.h"
return 0;
}
+
+int collecty_file_read_uint64(const char* path, uint64_t* number) {
+ unsigned long n = 0;
+ FILE* f = NULL;
+ int r;
+
+ // Open the file
+ f = fopen(path, "r");
+ if (!f)
+ return -errno;
+
+ // Read the number
+ r = fscanf(f, "%lu", &n);
+ if (r != 1) {
+ r = -errno;
+ goto ERROR;
+ }
+
+ // Return the number
+ *number = n;
+ r = 0;
+
+ERROR:
+ if (f)
+ fclose(f);
+
+ return r;
+}
#ifndef COLLECTY_UTIL_H
#define COLLECTY_UTIL_H
+#include <stdint.h>
+
#define collecty_format_number(buffer, number) \
__collecty_format_number(buffer, sizeof(buffer), number)
int __collecty_format_number(char* buffer, size_t length, int number);
+int collecty_file_read_uint64(const char* path, uint64_t* number);
+
#endif /* COLLECTY_UTIL_H */