sbase

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

commit 58dac5cf0abd4a354ff38d9beb542838447ff0a4
parent 1d28e5b981d3b7ea33234e49f90d6392bfdbc63b
Author: FRIGN <dev@frign.de>
Date:   Mon Jan 26 15:30:56 +0100

Add mandoc-manpage for mkdir(1) and clean up code

and mark it as finished in the README.

Diffstat:
README | 2+-
mkdir.1 | 52++++++++++++++++++++++++++++++++++------------------
mkdir.c | 30++++++++++++++----------------
3 files changed, 49 insertions(+), 35 deletions(-)
diff --git a/README b/README @@ -42,7 +42,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support, =* logname yes none = ls no -C, -R, -q, -u md5sum non-posix none -= mkdir yes none +=* mkdir yes none = mkfifo yes none = mktemp non-posix none = mv yes (-i) diff --git a/mkdir.1 b/mkdir.1 @@ -1,19 +1,35 @@ -.TH MKDIR 1 sbase\-VERSION -.SH NAME -mkdir \- make directory -.SH SYNOPSIS -.B mkdir -.RB [ \-pm ] -.RI [ name ...] -.SH DESCRIPTION -.B mkdir -creates the specified directories. -.SH OPTIONS -.TP -.B \-p -creates any necessary parent directories, and does not fail if the target +.Dd January 26, 2015 +.Dt MKDIR 1 sbase\-VERSION +.Sh NAME +.Nm mkdir +.Nd create directories +.Sh SYNOPSIS +.Nm mkdir +.Op Fl p +.Op Fl m Ar mode +.Ar name ... +.Sh DESCRIPTION +.Nm +creates a directory for each +.Ar name +if it does not already exist. +.Sh OPTIONS +.Bl -tag -width Ds +.It Fl m +Set the file +.Ar mode +of newly created directories. +.It Fl p +Also create necessary parent directories and +do not fail if +.Ar name already exists. -.B \-m -set the file permission bits of the newly created directory. -.SH SEE ALSO -.IR mkdir (2) +.El +.Sh SEE ALSO +.Xr mkdir 2 +.Sh STANDARDS +The +.Nm +utility is compliant with the +.St -p1003.1-2008 +specification. diff --git a/mkdir.c b/mkdir.c @@ -8,7 +8,20 @@ #include "util.h" -static void mkdirp(char *); +static void +mkdirp(char *path) +{ + char *p = 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 (p) + *p = '/'; + } while (p); +} static void usage(void) @@ -51,18 +64,3 @@ main(int argc, char *argv[]) return 0; } - -static void -mkdirp(char *path) -{ - char *p = 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 (p) - *p = '/'; - } while (p); -}