Hello,

just a quick thing I stumbled upon. Using arg.h here catches things like
"rmdir -p"
instead of attempting to actually delete the folder "-p".

This helps the user check what is implemented and what not instead of
silenty passing it on.

Cheers

FRIGN

-- 
FRIGN <d...@frign.de>
>From 013a887cce0a3c23852466c79fca46230b73a45b Mon Sep 17 00:00:00 2001
From: FRIGN <d...@frign.de>
Date: Mon, 9 Jun 2014 21:03:42 +0200
Subject: [PATCH] Refactor rmdir

Use arg.h- and pointer-iterator-idioms.
---
 rmdir.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/rmdir.c b/rmdir.c
index 5fdaadc..4578787 100644
--- a/rmdir.c
+++ b/rmdir.c
@@ -15,15 +15,18 @@ usage(void)
 int
 main(int argc, char *argv[])
 {
-	argv++;;
-	if(!*argv)
+	ARGBEGIN {
+	default:
 		usage();
+	} ARGEND;
 
-	while(*argv) {
-		if(rmdir(*argv++) == -1)
+	if (argc < 1)
+		usage();
+
+	for(; argc > 0; argc--, argv++)
+		if(rmdir(argv[0]) == -1)
 			fprintf(stderr, "rmdir: '%s': %s\n",
-					argv[-1], strerror(errno));
-	}
+					argv[0], strerror(errno));
 
 	return EXIT_SUCCESS;
 }
-- 
1.8.5.5

Reply via email to