summaryrefslogtreecommitdiffstats
path: root/src/libnetdata/inlined.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/libnetdata/inlined.h48
1 files changed, 37 insertions, 11 deletions
diff --git a/src/libnetdata/inlined.h b/src/libnetdata/inlined.h
index 6b71590c..50bc5e26 100644
--- a/src/libnetdata/inlined.h
+++ b/src/libnetdata/inlined.h
@@ -106,17 +106,6 @@ static inline uint64_t murmur64(uint64_t k) {
return k;
}
-static inline size_t indexing_partition(Word_t ptr, Word_t modulo) __attribute__((const));
-static inline size_t indexing_partition(Word_t ptr, Word_t modulo) {
-#ifdef ENV64BIT
- uint64_t hash = murmur64(ptr);
- return hash % modulo;
-#else
- uint32_t hash = murmur32(ptr);
- return hash % modulo;
-#endif
-}
-
static inline unsigned int str2u(const char *s) {
unsigned int n = 0;
@@ -506,6 +495,43 @@ static inline int read_txt_file(const char *filename, char *buffer, size_t size)
return 0;
}
+static inline bool read_txt_file_to_buffer(const char *filename, BUFFER *wb, size_t max_size) {
+ // Open the file
+ int fd = open(filename, O_RDONLY | O_CLOEXEC);
+ if (fd == -1)
+ return false;
+
+ // Get the file size
+ struct stat st;
+ if (fstat(fd, &st) == -1) {
+ close(fd);
+ return false;
+ }
+
+ size_t file_size = st.st_size;
+
+ // Check if the file size exceeds the maximum allowed size
+ if (file_size > max_size) {
+ close(fd);
+ return false; // File size too large
+ }
+
+ buffer_need_bytes(wb, file_size + 1);
+
+ // Read the file contents into the buffer
+ ssize_t r = read(fd, &wb->buffer[wb->len], file_size);
+ if (r != (ssize_t)file_size) {
+ close(fd);
+ return false; // Read error
+ }
+ wb->len = r;
+
+ // Close the file descriptor
+ close(fd);
+
+ return true; // Success
+}
+
static inline int read_proc_cmdline(const char *filename, char *buffer, size_t size) {
if (unlikely(!size)) return 3;