diff options
author | Lennart Weller <lhw@ring0.de> | 2017-09-17 22:17:45 +0000 |
---|---|---|
committer | Lennart Weller <lhw@ring0.de> | 2017-09-17 22:17:45 +0000 |
commit | 7ee3962eaca4214264964ae32c86de457a90e382 (patch) | |
tree | 5a784485351593ac6d74fa9fd9bbd8fe7c9c3fe0 /src/inlined.h | |
parent | maintscript eludes me (diff) | |
parent | New upstream version 1.8.0+dfsg (diff) | |
download | netdata-7ee3962eaca4214264964ae32c86de457a90e382.tar.xz netdata-7ee3962eaca4214264964ae32c86de457a90e382.zip |
Updated version 1.8.0+dfsg from 'upstream/1.8.0+dfsg'
with Debian dir 412de09d9bca38fe00146ef090f9e53f76493882
Diffstat (limited to 'src/inlined.h')
-rw-r--r-- | src/inlined.h | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/inlined.h b/src/inlined.h index f1812ba1c..9ab2dca73 100644 --- a/src/inlined.h +++ b/src/inlined.h @@ -244,26 +244,48 @@ static inline char *strncpyz(char *dst, const char *src, size_t n) { return p; } -static inline int read_single_number_file(const char *filename, unsigned long long *result) { - char buffer[30 + 1]; - +static inline int read_file(const char *filename, char *buffer, size_t size) { int fd = open(filename, O_RDONLY, 0666); - if(unlikely(fd == -1)) { - *result = 0; + if(unlikely(fd == -1)) return 1; - } - ssize_t r = read(fd, buffer, 30); + ssize_t r = read(fd, buffer, size); if(unlikely(r == -1)) { - *result = 0; close(fd); return 2; } + buffer[r] = '\0'; close(fd); + return 0; +} + +static inline int read_single_number_file(const char *filename, unsigned long long *result) { + char buffer[30 + 1]; + + int ret = read_file(filename, buffer, 30); + if(unlikely(ret)) { + *result = 0; + return ret; + } + buffer[30] = '\0'; *result = str2ull(buffer); return 0; } +static inline int read_single_signed_number_file(const char *filename, long long *result) { + char buffer[30 + 1]; + + int ret = read_file(filename, buffer, 30); + if(unlikely(ret)) { + *result = 0; + return ret; + } + + buffer[30] = '\0'; + *result = atoll(buffer); + return 0; +} + #endif //NETDATA_INLINED_H |