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

and mark it as finished in the README.
This commit is contained in:
FRIGN 2015-01-26 15:30:56 +01:00
parent 1d28e5b981
commit 58dac5cf0a
3 changed files with 49 additions and 35 deletions

2
README
View File

@ -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)

52
mkdir.1
View File

@ -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.

30
mkdir.c
View File

@ -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);
}