]> pd.if.org Git - zpackage/commitdiff
add zpm program to quote strings for sqlite
authorNathan Wagner <nw@hydaspes.if.org>
Sat, 15 Sep 2018 08:19:27 +0000 (08:19 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Mon, 17 Sep 2018 12:13:04 +0000 (12:13 +0000)
zpm-quote.c [new file with mode: 0644]

diff --git a/zpm-quote.c b/zpm-quote.c
new file mode 100644 (file)
index 0000000..ea306b4
--- /dev/null
@@ -0,0 +1,28 @@
+#include <stdlib.h>
+
+#include "zpm.h"
+
+/* for quoting against the shell replace ' with '\'' and surround with
+ * single quotes
+ */
+int main(int ac, char **av) {
+       size_t n = 0;
+       size_t bufsize = 0;
+       char *buffer = 0;
+       int i;
+
+       for (i=1;i<ac;i++) {
+               n = zpm_quote(av[i], 0, 0);
+               if (n+1 > bufsize) {
+                       buffer = realloc(buffer, n+1);
+                       if (buffer) {
+                               bufsize = n+1;
+                       } else {
+                               exit(EXIT_FAILURE);
+                       }
+               }
+               zpm_quote(av[i], buffer, bufsize);
+               printf("%s\n", buffer);
+       }
+       return 0;
+}