diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-11-25 14:45:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-11-25 15:28:16 +0000 |
commit | 5e1bf7f1473ac3099948e1406d4ea8ba4af2be95 (patch) | |
tree | 524889e5becb81643bf8741e3082955dca076f09 /src/libnetdata/inlined.h | |
parent | Releasing debian version 1.47.5-1. (diff) | |
download | netdata-5e1bf7f1473ac3099948e1406d4ea8ba4af2be95.tar.xz netdata-5e1bf7f1473ac3099948e1406d4ea8ba4af2be95.zip |
Merging upstream version 2.0.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/libnetdata/inlined.h')
-rw-r--r-- | src/libnetdata/inlined.h | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/src/libnetdata/inlined.h b/src/libnetdata/inlined.h index 6b71590c9..50bc5e269 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; |