]> git.ipfire.org Git - people/stevee/perl-ipset.git/commitdiff
Add function to capture printed content and store it.
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 31 Aug 2022 18:32:27 +0000 (20:32 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Wed, 31 Aug 2022 18:32:27 +0000 (20:32 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
IPSet.xs

index 82a9810ac68a36d3009f44cd8e1f0257fa95b5d7..507f94a9a911fe5a26440b309c77623347d49a73 100644 (file)
--- a/IPSet.xs
+++ b/IPSet.xs
 #include <libipset/session.h>
 #include <libipset/types.h>
 
+static int print_outfm_to_string(struct ipset_session *session,
+        void *p,
+        const char *fmt, ...)
+{
+        char** output = (char**)p;
+        va_list args;
+        int r;
+
+       char* buffer = NULL;
+
+        va_start(args, fmt);
+        r = vasprintf(&buffer, fmt, args);
+        va_end(args);
+
+       if (r < 0)
+               goto ERROR;
+
+       // Append
+       r = asprintf(output, "%s%s", (output && *output) ? *output : "", buffer);
+       if (r < 0)
+               goto ERROR;
+
+       // Success
+       r = 0;
+
+ERROR:
+       if (buffer)
+               free(buffer);
+
+        return r;
+}
+
 MODULE = IPSet         PACKAGE = IPSet
 
 struct ipset_session *