tcreate polls/ and improve error messaging - vote - simple cgi voting system for web and gopher (HTM) git clone git://src.adamsgaard.dk/vote (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit 7be65d231cd9ea138f2aaa8e06a1ad6c2dc496be (DIR) parent 71c26ce31eeddf5ccbc2e56c10281ca742648364 (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Sun, 27 Sep 2020 00:45:20 +0200 create polls/ and improve error messaging Diffstat: M vote.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) --- (DIR) diff --git a/vote.c b/vote.c t@@ -2,6 +2,8 @@ #include <stdlib.h> #include <unistd.h> #include <string.h> +#include <sys/stat.h> +#include <errno.h> #define OUT(s) (fputs((s), stdout)) t@@ -38,11 +40,18 @@ main() { char *query; char *q; - if (pledge("stdio", NULL) == -1) { + if (pledge("stdio cpath", NULL) == -1) { + fprintf(stderr, "pledge: %s\n", strerror(errno)); OUT("Status: 500 Internal Server Error\r\n\r\n"); exit(1); } + if (mkdir("polls", 644) == -1) { + fprintf(stderr, "mkdir polls/ failed: %s\n", strerror(errno)); + OUT("Status: 500 Internal Server Error\r\n\r\n"); + exit(0); + } + if (!(query = getenv("QUERY_STRING"))) query = "";