#include #include #include "sqlite3.h" int zpm_quote(char *value, char *dest, size_t n) { size_t dlen = 0; int nch = 0; char *s; /* figure out length of quoted string */ for (s = value; *s; s++) { dlen++; if (*s == '\'') dlen++; } /* if there's enough room for the string and the terminating null * byte, quote the string */ if (dest && dlen < n) { while (*value) { if (*value == '\'') { *dest++ = '\''; nch++; } *dest++ = *value++; nch++; } dest[nch] = 0; } /* returns either the number of characters written or would * be written */ return dlen; }