sbase

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

commit 9119365c91de233a0cd13d2dd2016caa9703bee4
parent befec8cf677ba01674ac5997fb83623177ceb151
Author: FRIGN <dev@frign.de>
Date:   Wed, 28 Jan 2015 20:57:32 +0100

Add full mode support to mkdir(1) and fix return values

Same as with mkfifo(1). Also, somehow the return-values were
ignored and it would always return 0 no matter how many errors
happened.

Diffstat:
mkdir.c | 23++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/mkdir.c b/mkdir.c @@ -29,16 +29,17 @@ mkdirp(char *path) static void usage(void) { - eprintf("usage: %s [-pm] directory...\n", argv0); + eprintf("usage: %s [-p] [-m mode] directory ...\n", argv0); } int main(int argc, char *argv[]) { - int pflag = 0; - int mflag = 0; - int mode; - int r = 0; + mode_t mode = 0; + mode_t mask; + int pflag = 0; + int mflag = 0; + int ret = 0; ARGBEGIN { case 'p': @@ -46,7 +47,8 @@ main(int argc, char *argv[]) break; case 'm': mflag = 1; - mode = estrtol(EARGF(usage()), 8); + mask = getumask(); + mode = parsemode(EARGF(usage()), mode, mask); break; default: usage(); @@ -58,18 +60,17 @@ main(int argc, char *argv[]) for (; argc > 0; argc--, argv++) { if (pflag) { if (mkdirp(argv[0]) < 0) - r = 1; + ret = 1; } else if (mkdir(argv[0], S_IRWXU|S_IRWXG|S_IRWXO) < 0) { weprintf("mkdir %s:", argv[0]); - r = 1; + ret = 1; } if (mflag) { if (chmod(argv[0], mode) < 0) { weprintf("chmod %s:", argv[0]); - r = 1; + ret = 1; } } } - - return 0; + return ret; }