[hackers] [sbase] mkdir: Don't stop after the first failure || sin

From: <git_AT_suckless.org>
Date: Mon, 26 Jan 2015 16:10:41 +0100 (CET)

commit 1c2b88b5fac2b039c9cc336be61f2a46ca13a874
Author: sin <sin_AT_2f30.org>
Date: Mon Jan 26 15:09:26 2015 +0000

    mkdir: Don't stop after the first failure

diff --git a/mkdir.c b/mkdir.c
index a64051a..095643f 100644
--- a/mkdir.c
+++ b/mkdir.c
_AT_@ -8,7 +8,7 @@
 
 #include "util.h"
 
-static void
+static int
 mkdirp(char *path)
 {
         char *p = path;
_AT_@ -16,11 +16,14 @@ mkdirp(char *path)
         do {
                 if (*p && (p = strchr(&p[1], '/')))
                         *p = '\0';
- if (mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO) < 0 && errno != EEXIST)
- eprintf("mkdir %s:", path);
+ if (mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO) < 0 && errno != EEXIST) {
+ weprintf("mkdir %s:", path);
+ return -1;
+ }
                 if (p)
                         *p = '/';
         } while (p);
+ return 0;
 }
 
 static void
_AT_@ -35,6 +38,7 @@ main(int argc, char *argv[])
         int pflag = 0;
         int mflag = 0;
         int mode;
+ int r = 0;
 
         ARGBEGIN {
         case 'p':
_AT_@ -53,13 +57,18 @@ main(int argc, char *argv[])
 
         for (; argc > 0; argc--, argv++) {
                 if (pflag) {
- mkdirp(argv[0]);
+ if (mkdirp(argv[0]) < 0)
+ r = 1;
                 } else if (mkdir(argv[0], S_IRWXU|S_IRWXG|S_IRWXO) < 0) {
- eprintf("mkdir %s:", argv[0]);
+ weprintf("mkdir %s:", argv[0]);
+ r = 1;
+ }
+ if (mflag) {
+ if (chmod(argv[0], mode) < 0) {
+ weprintf("chmod %s:", argv[0]);
+ r = 1;
+ }
                 }
- if (mflag)
- if (chmod(argv[0], mode) < 0)
- eprintf("chmod %s:", argv[0]);
         }
 
         return 0;
Received on Mon Jan 26 2015 - 16:10:41 CET

This archive was generated by hypermail 2.3.0 : Mon Jan 26 2015 - 16:12:09 CET