-#include <stdarg.h>
-
-static void die(char *msg) {
- fprintf(stderr, "%s", msg);
- exit(1);
-}
-
-static char *mkString(const char *fmt, ...) {
- char *p;
- int i, j;
- va_list argp;
-
- va_start(argp, fmt);
- i = vsnprintf(p, 0, fmt, argp);
- va_end(argp);
-
- if (i < 0) {
- die("snprintf failed\n");
- }
-
- p = malloc(i + 1);
- if (p == NULL) {
- die("malloc failed\n");
- }
-
- va_start(argp, fmt);
- j = vsnprintf(p, i + 1, fmt, argp);
- va_end(argp);
- if (i < 0) {
- die("snprintf failed\n");
- }
-
- return p;
-}
-
-char *quote(char *str) {
- char *quotedStr;
- char *p;
- int i;
-
- quotedStr = malloc(2 * strlen(str) + 2 + 1);
- if (quotedStr == NULL) {
- die("malloc failed\n");
- }
- p = quotedStr;
- *p++ = '"';
- while (*str) {
- if (*str == '"') {
- *p++ = '\\';
- }
- *p++ = *str++;
- }
- *p++ = '"';
- *p = '\0';
-
- return quotedStr;
-}