sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit d00d73fd4a17d2c266e6e22095c964f50044370e
parent 58dac5cf0abd4a354ff38d9beb542838447ff0a4
Author: sin <sin@2f30.org>
Date:   Mon, 26 Jan 2015 15:09:26 +0000

mkdir: Don't stop after the first failure

Diffstat:
Mmkdir.c | 25+++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/mkdir.c b/mkdir.c @@ -8,7 +8,7 @@ #include "util.h" -static void +static int mkdirp(char *path) { char *p = path; @@ -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 @@ -35,6 +38,7 @@ main(int argc, char *argv[]) int pflag = 0; int mflag = 0; int mode; + int r = 0; ARGBEGIN { case 'p': @@ -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;