[hackers] [sbase] Add full mode support to mkdir(1) and fix return values || FRIGN

From: <git_AT_suckless.org>
Date: Tue, 24 Mar 2015 23:53:19 +0100 (CET)

commit 9119365c91de233a0cd13d2dd2016caa9703bee4
Author: FRIGN <dev_AT_frign.de>
Date: Wed Jan 28 20:57:32 2015 +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.

diff --git a/mkdir.c b/mkdir.c
index 095643f..e1380a3 100644
--- a/mkdir.c
+++ b/mkdir.c
_AT_@ -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':
_AT_@ -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();
_AT_@ -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;
 }
Received on Tue Mar 24 2015 - 23:53:19 CET

This archive was generated by hypermail 2.3.0 : Wed Mar 25 2015 - 00:03:58 CET