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 =* logname yes none
= ls no -C, -R, -q, -u = ls no -C, -R, -q, -u
md5sum non-posix none md5sum non-posix none
= mkdir yes none =* mkdir yes none
= mkfifo yes none = mkfifo yes none
= mktemp non-posix none = mktemp non-posix none
= mv yes (-i) = mv yes (-i)

52
mkdir.1
View File

@ -1,19 +1,35 @@
.TH MKDIR 1 sbase\-VERSION .Dd January 26, 2015
.SH NAME .Dt MKDIR 1 sbase\-VERSION
mkdir \- make directory .Sh NAME
.SH SYNOPSIS .Nm mkdir
.B mkdir .Nd create directories
.RB [ \-pm ] .Sh SYNOPSIS
.RI [ name ...] .Nm mkdir
.SH DESCRIPTION .Op Fl p
.B mkdir .Op Fl m Ar mode
creates the specified directories. .Ar name ...
.SH OPTIONS .Sh DESCRIPTION
.TP .Nm
.B \-p creates a directory for each
creates any necessary parent directories, and does not fail if the target .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. already exists.
.B \-m .El
set the file permission bits of the newly created directory. .Sh SEE ALSO
.SH SEE ALSO .Xr mkdir 2
.IR 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" #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 static void
usage(void) usage(void)
@ -51,18 +64,3 @@ main(int argc, char *argv[])
return 0; 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);
}