]> git.ipfire.org Git - telemetry.git/commitdiff
file: Allow to open a buffer as a file object
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 8 Oct 2025 15:44:58 +0000 (15:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 8 Oct 2025 15:44:58 +0000 (15:44 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/file.c
src/daemon/file.h

index a3162349aa664ebb6136b85aea4ebad3d071dd57..71153e3230c4088dd42aa818f06a0036ab326fd1 100644 (file)
@@ -91,6 +91,33 @@ ERROR:
        return r;
 }
 
+int collecty_file_open_buffer(collecty_file** file, collecty_ctx* ctx, collecty_buffer* buffer) {
+       collecty_file* self = NULL;
+       int r;
+
+       // Create a new object
+       r = collecty_file_create(&self, ctx);
+       if (r < 0)
+               goto ERROR;
+
+       // Open the buffer as a file
+       self->f = collecty_buffer_fopen(buffer, "r");
+       if (!self->f) {
+               r = -errno;
+               goto ERROR;
+       }
+
+       // Return the pointer
+       *file = self;
+       return 0;
+
+ERROR:
+       if (self)
+               collecty_file_unref(self);
+
+       return r;
+}
+
 collecty_file* collecty_file_ref(collecty_file* self) {
        ++self->nrefs;
        return self;
index dc3ddc046a8c136ee8d90cd1ef1b6b35a84ddfa6..9f51ac07a24b6bdab223c4e798e45a2b21632891 100644 (file)
 
 typedef struct collecty_file collecty_file;
 
+#include "buffer.h"
 #include "ctx.h"
 
 int collecty_file_open_path(collecty_file** file, collecty_ctx* ctx, const char* path);
+int collecty_file_open_buffer(collecty_file** file, collecty_ctx* ctx, collecty_buffer* buffer);
 
 collecty_file* collecty_file_ref(collecty_file* self);
 collecty_file* collecty_file_unref(collecty_file* self);