From: Michael Tremer Date: Wed, 8 Oct 2025 16:10:12 +0000 (+0000) Subject: util: Remove the old file walking functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce68cffd9e6f3e8d7840f3e22a9791f4c34e057a;p=telemetry.git util: Remove the old file walking functions Signed-off-by: Michael Tremer --- diff --git a/src/daemon/parse.c b/src/daemon/parse.c index be18f39..191a0ac 100644 --- a/src/daemon/parse.c +++ b/src/daemon/parse.c @@ -19,6 +19,7 @@ #############################################################################*/ #include +#include #include "parse.h" #include "string.h" diff --git a/src/daemon/string.h b/src/daemon/string.h index 4114770..ea13db8 100644 --- a/src/daemon/string.h +++ b/src/daemon/string.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "util.h" diff --git a/src/daemon/util.c b/src/daemon/util.c index 48224b6..57b86b6 100644 --- a/src/daemon/util.c +++ b/src/daemon/util.c @@ -20,7 +20,6 @@ #include #include -#include #include #include "string.h" @@ -51,67 +50,3 @@ int collecty_format_title(char** title, const char* format, ...) { return 0; } - -int collecty_fwalk(FILE* f, collecty_fwalk_callback callback, void* data) { - char* line = NULL; - size_t length = 0; - size_t l = 0; - int r; - - // Start at the beginning of the stream - r = fseek(f, 0L, SEEK_SET); - if (r < 0) - return -errno; - - // Walk through all lines - for (;;) { - // Fetch the next line - r = getline(&line, &length, f); - if (r < 0) { - // Reset r if have reached the end of the file - if (feof(f)) - r = 0; - - break; - } - - // Remove the trailing newline - collecty_string_rstrip(line); - - // Determine the length of the line - l = strlen(line); - - // Call the callback - r = callback(line, l, data); - if (r < 0) - break; - } - - // Cleanup - if (line) - free(line); - - return r; -} - -int collecty_fwalk_buffer(const char* buffer, const size_t length, - collecty_fwalk_callback callback, void* data) { - FILE* f = NULL; - int r; - - // Open as a file handle - f = fmemopen((char*)buffer, length, "r"); - if (!f) { - r = -errno; - goto ERROR; - } - - // Walk through all lines - r = collecty_fwalk(f, callback, data); - -ERROR: - if (f) - fclose(f); - - return r; -} diff --git a/src/daemon/util.h b/src/daemon/util.h index aea5718..295b939 100644 --- a/src/daemon/util.h +++ b/src/daemon/util.h @@ -21,9 +21,7 @@ #ifndef COLLECTY_UTIL_H #define COLLECTY_UTIL_H -#include -#include -#include +#include // Preprocessor macro to make something a string #define STRINGIFY(x) #x @@ -50,11 +48,4 @@ int __collecty_format_number(char* buffer, size_t length, int number); int collecty_format_title(char** title, const char* format, ...) __attribute__((format(printf, 2, 3))); -typedef int (*collecty_fwalk_callback)(const char* line, const size_t length, void* data); - -int collecty_fwalk(FILE* f, collecty_fwalk_callback callback, void* data); - -int collecty_fwalk_buffer(const char* buffer, const size_t length, - collecty_fwalk_callback callback, void* data); - #endif /* COLLECTY_UTIL_H */