[hackers] [sbase] Three bugfixes in mkdir(1) || FRIGN

From: <git_AT_suckless.org>
Date: Fri, 13 Mar 2015 12:41:21 +0100 (CET)

commit 776ead406a4c9e838c6e3427b80bd8210a559e36
Author: FRIGN <dev_AT_frign.de>
Date: Fri Mar 13 12:15:30 2015 +0100

    Three bugfixes in mkdir(1)
    
    1) Any path passed to mkdir -p beginning with '/' failed, because
       it would cut out the first '/' immediately, passing "" to mkdir.
    2) Running mkdir -p with a path/to/dir without trailing '/' would
       not create the directory.
       This is due to a wrong flag-check I added in the main-loop.
       It should now work as expected.
    3) With the p-flag given, don't report an error in case the last
       dir also exists.

diff --git a/mkdir.c b/mkdir.c
index 470c07e..b0d8bc2 100644
--- a/mkdir.c
+++ b/mkdir.c
_AT_@ -11,7 +11,7 @@ mkdirp(char *path)
 {
         char *p;
 
- for (p = path; *p; p++) {
+ for (p = path + (*path == '/'); *p; p++) {
                 if (*p != '/')
                         continue;
                 *p = '\0';
_AT_@ -56,9 +56,11 @@ main(int argc, char *argv[])
         for (; *argv; argc--, argv++) {
                 if (pflag && mkdirp(*argv) < 0) {
                         ret = 1;
- } else if (!pflag && mkdir(*argv, S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
- weprintf("mkdir %s:", *argv);
- ret = 1;
+ } else if (mkdir(*argv, S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
+ if (!(pflag && errno == EEXIST)) {
+ weprintf("mkdir %s:", *argv);
+ ret = 1;
+ }
                 } else if (mflag && chmod(*argv, mode) < 0) {
                         weprintf("chmod %s:", *argv);
                         ret = 1;
Received on Fri Mar 13 2015 - 12:41:21 CET

This archive was generated by hypermail 2.3.0 : Fri Mar 13 2015 - 12:48:14 CET