coreutils

General Software Utilities
git clone http://git.omkov.net/coreutils
Log | Tree | Refs | README | LICENCE | Download

AuthorJamozed <[email protected]>
Date2020-07-06 11:25:19
Commit7b4e9b3c2ae70dbb628c8c4dc985ba8114d71bb9
Parent5ee88034400c39b9850454dcf52972af5ec76f20

rmdir: Use libokv error reporting

Diffstat

M src/rmdir.c | 25 ++++++++++++-------------

1 files changed, 12 insertions, 13 deletions

diff --git a/src/rmdir.c b/src/rmdir.c
index 95da7d0..da6eb9e 100644
--- a/src/rmdir.c
+++ b/src/rmdir.c
@@ -1,4 +1,4 @@
-// rmdir.c, version 1.0.0
+// rmdir.c, version 1.0.1
 // OMKOV coreutils implementation of POSIX rmdir
 // Copyright (C) 2020, Jakob Wakeling
 // All rights reserved.
@@ -33,22 +33,23 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 */
 
-#include "error.h"
 #include "optget.h"
 
+#include <error.h>
+
 #include <unistd.h>
 
-#include <errno.h>
 #include <stdbool.h>
 #include <stdio.h>
-#include <string.h>
+
+#define VERSION "1.0.1"
 
 static bool pflag;
 
 static void help(void);
 static void version(void);
 
-int main(int argc, char *argv[]) {
+int main(int ac, char *av[]) { A0 = av[0];
 	lop_t lops[] = {
 		{ "help",    ARG_NUL, 256 },
 		{ "version", ARG_NUL, 257 },
@@ -56,25 +57,23 @@ int main(int argc, char *argv[]) {
 	};
 
 	opt_t opt = OPTGET_INIT; opt.str = "p"; opt.lops = lops; int o;
-	while ((o = optget(&opt, argv, 1)) != -1) switch (o) {
+	while ((o = optget(&opt, av, 1)) != -1) switch (o) {
 	case 'p': { pflag = true; break; }
 	case 256: { help(); return 0; }
 	case 257: { version(); return 0; }
 	default: { return 1; }
 	}
 
-	if (opt.ind == argc) { error(1, "%s: missing operand", argv[0]); }
+	if (opt.ind == ac) { error(1, "missing operand"); }
 
-	for (char **p = &argv[opt.ind]; *p; ++p) {
-		if (rmdir(*p)) { warn("%s: %s: %s", argv[0], *p, serrno); continue; }
+	for (char **p = &av[opt.ind]; *p; ++p) {
+		if (rmdir(*p)) { warn("%s: %s", *p, serr()); continue; }
 		if (pflag) {
 			char *c = *p; for (; *c; ++c);
 			for (--c; *p < c && *(c - 1) == '/'; --c);
 			for (*c = 0; *p < c; --c) {
 				if (*c != '/' || *(c - 1) == '/') { continue; }
-				*c = 0; if (rmdir(*p)) {
-					warn("%s: %s: %s", argv[0], *p, serrno); break;
-				}
+				*c = 0; if (rmdir(*p)) { warn("%s: %s", *p, serr()); break; }
 			}
 		}
 	}
@@ -93,7 +92,7 @@ static void help(void) {
 }
 
 static void version(void) {
-	puts("OMKOV coreutils rmdir, version 1.0.0");
+	puts("OMKOV coreutils rmdir, version " VERSION);
 	puts("Copyright (C) 2020, Jakob Wakeling");
 	puts("All rights reserved.");
 	puts("OMKOV Permissive Licence (https://www.omkov.net/OLPE)");