]> arthur.barton.de Git - netdata.git/blobdiff - src/common.c
cgroups now also read usage_in_bytes, memsw_usage_in_bytes, failcnt and creates 2...
[netdata.git] / src / common.c
index 64d50f636e9ec756d8f3fdf4558af39e74bdc82e..6f162672cf76a80f2b9b8e9f4d656a0a578b9f64 100644 (file)
@@ -1126,3 +1126,20 @@ void get_system_HZ(void) {
 
     hz = (unsigned int) ticks;
 }
+
+int read_single_number_file(const char *filename, unsigned long long *result) {
+    char buffer[1024 + 1];
+
+    int fd = open(filename, O_RDONLY, 0666);
+    if(unlikely(fd == -1)) return 1;
+
+    ssize_t r = read(fd, buffer, 1024);
+    if(unlikely(r == -1)) {
+        close(fd);
+        return 2;
+    }
+
+    close(fd);
+    *result = strtoull(buffer, NULL, 0);
+    return 0;
+}