Remove trailing slash from srvroot, if present

This commit is contained in:
Camden Dixie O'Brien 2022-10-13 17:10:53 +01:00
parent f171687fda
commit f6871a7922

7
main.c
View File

@ -73,13 +73,16 @@ int main(int argc, char *argv[])
* Get srvroot path from arguments and copy into pbuf. * Get srvroot path from arguments and copy into pbuf.
* *
* The srvroot being at the start of pbuf should be maintained * 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) { if (argc < 2) {
fprintf(stderr, "Usage: %s srvroot\n", argv[0]); fprintf(stderr, "Usage: %s srvroot\n", argv[0]);
return EXIT_FAILURE; 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) { if (srvroot_len > PBUF_SIZE) {
fprintf(stderr, "srvroot path is too long\n"); fprintf(stderr, "srvroot path is too long\n");
return EXIT_FAILURE; return EXIT_FAILURE;