diff --git a/main.c b/main.c index ff84858..4982080 100644 --- a/main.c +++ b/main.c @@ -73,13 +73,16 @@ int main(int argc, char *argv[]) * Get srvroot path from arguments and copy into pbuf. * * The srvroot being at the start of pbuf should be maintained - * through the whole application. + * through the whole application. Any trailing '/' is removed if + * present. */ if (argc < 2) { fprintf(stderr, "Usage: %s srvroot\n", argv[0]); return EXIT_FAILURE; } - const size_t srvroot_len = strlen(argv[1]); + size_t srvroot_len = strlen(argv[1]); + if (argv[1][srvroot_len - 1] == '/') + --srvroot_len; if (srvroot_len > PBUF_SIZE) { fprintf(stderr, "srvroot path is too long\n"); return EXIT_FAILURE;