logo

utils-std

Collection of commonly available Unix tools
commit: e060d81129e1b69ca72c2b873dab7881a38a9230
parent f7260c344d96502f16171c31b0b44050f00b0b95
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue,  9 Apr 2024 16:23:49 +0200

cmd/mkdir: Handle getopt errors, abort on default

Diffstat:

Mcmd/mkdir.c11+++++++++++
1 file changed, 11 insertions(+), 0 deletions(-)

diff --git a/cmd/mkdir.c b/cmd/mkdir.c @@ -11,6 +11,7 @@ #include <limits.h> // PATH_MAX #include <stdbool.h> #include <stdio.h> // fprintf +#include <stdlib.h> // abort #include <string.h> // strerror, strrchr #include <sys/stat.h> // mkdir #include <unistd.h> // getopt @@ -104,6 +105,16 @@ main(int argc, char *argv[]) return 1; } break; + case ':': + fprintf(stderr, "mkdir: Error: Missing operand for option: '-%c'\n", optopt); + usage(); + return 1; + case '?': + fprintf(stderr, "mkdir: Error: Unrecognised option: '-%c'\n", optopt); + usage(); + return 1; + default: + abort(); } }