[hackers] [sbase] Implement -m option for mkdir || sin

From: <git_AT_suckless.org>
Date: Sat, 05 Oct 2013 16:29:25 +0200

commit 4d014e66fd13503a71ad424a333c7c69692b23e8
Author: sin <sin_AT_2f30.org>
Date: Sat Aug 31 22:51:25 2013 +0100

    Implement -m option for mkdir

diff --git a/mkdir.1 b/mkdir.1
index 3992e8f..31d1728 100644
--- a/mkdir.1
+++ b/mkdir.1
_AT_@ -3,7 +3,7 @@
 mkdir \- make directory
 .SH SYNOPSIS
 .B mkdir
-.RB [ \-p ]
+.RB [ \-pm ]
 .RI [ name ...]
 .SH DESCRIPTION
 .B mkdir
_AT_@ -13,5 +13,7 @@ creates the specified directories.
 .B \-p
 creates any necessary parent directories, and does not fail if the target
 already exists.
+.B \-m
+set the file permission bits of the newly created directory.
 .SH SEE ALSO
 .IR mkdir (2)
diff --git a/mkdir.c b/mkdir.c
index a6eafa3..57b2382 100644
--- a/mkdir.c
+++ b/mkdir.c
_AT_@ -1,4 +1,5 @@
 /* See LICENSE file for copyright and license details. */
+#include <sys/stat.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdbool.h>
_AT_@ -13,18 +14,24 @@ static void mkdirp(char *);
 static void
 usage(void)
 {
- eprintf("usage: %s [-p] directory...
", argv0);
+ eprintf("usage: %s [-pm] directory...
", argv0);
 }
 
 int
 main(int argc, char *argv[])
 {
         bool pflag = false;
+ bool mflag = false;
+ int mode;
 
         ARGBEGIN {
         case 'p':
                 pflag = true;
                 break;
+ case 'm':
+ mflag = true;
+ mode = estrtol(EARGF(usage()), 10);
+ break;
         default:
                 usage();
         } ARGEND;
_AT_@ -38,6 +45,9 @@ main(int argc, char *argv[])
                 } else if(mkdir(argv[0], S_IRWXU|S_IRWXG|S_IRWXO) == -1) {
                         eprintf("mkdir %s:", argv[0]);
                 }
+ if (mflag)
+ if (chmod(argv[0], mode) < 0)
+ eprintf("chmod %s:", argv[0]);
         }
 
         return 0;
Received on Sat Oct 05 2013 - 16:29:25 CEST

This archive was generated by hypermail 2.3.0 : Sat Oct 05 2013 - 16:36:31 CEST