commit 231bfcdc0391cde9077e6ae0cd14dc6831fb1b88 from: Omar Polo date: Mon Dec 21 13:38:31 2020 UTC make -d handle correctly non-absolute paths before the -d option only accepted absolute paths, and this wasn't documented. Even more, with the default value of "docs" it won't work. Now it transforms all relative paths to absolute paths before going on. commit - dd3e110a707fc9ac5653969b22e6489f7e100d50 commit + 231bfcdc0391cde9077e6ae0cd14dc6831fb1b88 blob - 1e57bcada8f62c5281cccb3658290ad8c999a8b9 blob + e5cf21de057c543cc316c667a0ccab5ec6042eff --- gmid.c +++ gmid.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -990,6 +991,21 @@ loop(struct tls *ctx, int sock) handle(&fds[i], &clients[i]); } } +} + +char * +absolutify_path(const char *path) +{ + char *wd, *r; + + if (*path == '/') + return strdup(path); + + wd = getwd(NULL); + if (asprintf(&r, "%s/%s", wd, path) == -1) + err(1, "asprintf"); + free(wd); + return r; } void @@ -1019,7 +1035,7 @@ main(int argc, char **argv) connected_clients = 0; - dir = "docs/"; + dir = absolutify_path("docs"); cgi = NULL; port = 1965; foreground = 0; @@ -1031,7 +1047,9 @@ main(int argc, char **argv) break; case 'd': - dir = optarg; + free((char*)dir); + if ((dir = absolutify_path(optarg)) == NULL) + err(1, "absolutify_path"); break; case 'f':