[klibc] [patch] mkdir use and add usage

maximilian attems maks at sternwelten.at
Thu Aug 24 13:43:25 PDT 2006


please pull
git://charm.itp.tuwien.ac.at/mattems/klibc/.git maks


commit b0c5c2b8ee60d91cb96541339c6be8108d0e2131
Author: maximilian attems <maks at sternwelten.at>
Date:   Thu Aug 24 22:40:23 2006 +0200

    [klibc] mkdir add usage
    when printing errors about cli switches, point out the expected usage.
    patches adds usage function and calls to it.
    
    Signed-off-by: maximilian attems <maks at sternwelten.at>

diff --git a/usr/utils/mkdir.c b/usr/utils/mkdir.c
index 1275472..af241ef 100644
--- a/usr/utils/mkdir.c
+++ b/usr/utils/mkdir.c
@@ -15,6 +15,12 @@ static int p_flag;
 
 char *progname;
 
+static __noreturn usage(void)
+{
+	fprintf(stderr, "Usage: %s [-p] [-m mode] dir...\n", progname);
+	exit(1);
+}
+
 static int make_one_dir(char *dir, mode_t mode)
 {
 	struct stat stbuf;
@@ -131,14 +137,12 @@ int main(int argc, char *argv[])
 		case '?':
 			fprintf(stderr, "%s: invalid option -%c\n",
 				progname, optopt);
-			exit(1);
+			usage();
 		}
 	} while (1);
 
-	if (optind == argc) {
-		fprintf(stderr, "Usage: %s [-p] [-m mode] dir...\n", progname);
-		exit(1);
-	}
+	if (optind == argc)
+		usage();
 
 	while (optind < argc) {
 		if (make_dir(argv[optind]))
-- 
maks



More information about the klibc mailing list