add mkdir
This commit is contained in:
parent
6c7f288bd8
commit
5629972223
2
Makefile
2
Makefile
|
@ -2,7 +2,7 @@ include config.mk
|
||||||
|
|
||||||
LIB = util/afgets.o util/agetcwd.o util/enmasse.o util/eprintf.o util/recurse.o
|
LIB = util/afgets.o util/agetcwd.o util/enmasse.o util/eprintf.o util/recurse.o
|
||||||
SRC = basename.c cat.c chown.c date.c dirname.c echo.c false.c grep.c head.c \
|
SRC = basename.c cat.c chown.c date.c dirname.c echo.c false.c grep.c head.c \
|
||||||
ln.c ls.c mkfifo.c pwd.c rm.c sleep.c tee.c touch.c true.c wc.c
|
ln.c ls.c mkdir.c mkfifo.c pwd.c rm.c sleep.c tee.c touch.c true.c wc.c
|
||||||
OBJ = $(SRC:.c=.o) $(LIB)
|
OBJ = $(SRC:.c=.o) $(LIB)
|
||||||
BIN = $(SRC:.c=)
|
BIN = $(SRC:.c=)
|
||||||
MAN = $(SRC:.c=.1)
|
MAN = $(SRC:.c=.1)
|
||||||
|
|
17
mkdir.1
Normal file
17
mkdir.1
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
.TH MKDIR 1 sbase\-VERSION
|
||||||
|
.SH NAME
|
||||||
|
mkdir \- make directory
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.B mkdir
|
||||||
|
.RB [ \-p ]
|
||||||
|
.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
|
||||||
|
already exists.
|
||||||
|
.SH SEE ALSO
|
||||||
|
.IR mkdir (2)
|
48
mkdir.c
Normal file
48
mkdir.c
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
static void mkdirp(char *);
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
bool pflag = false;
|
||||||
|
char c;
|
||||||
|
|
||||||
|
while((c = getopt(argc, argv, "p")) != -1)
|
||||||
|
switch(c) {
|
||||||
|
case 'p':
|
||||||
|
pflag = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
for(; optind < argc; optind++)
|
||||||
|
if(pflag)
|
||||||
|
mkdirp(argv[optind]);
|
||||||
|
else if(mkdir(argv[optind], S_IRWXU|S_IRWXG|S_IRWXO) != 0)
|
||||||
|
eprintf("mkdir %s:", argv[optind]);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mkdirp(char *path)
|
||||||
|
{
|
||||||
|
char *p = path;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if((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);
|
||||||
|
}
|
1
pwd.c
1
pwd.c
|
@ -1,7 +1,6 @@
|
||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
6
touch.1
6
touch.1
|
@ -1,6 +1,6 @@
|
||||||
.TH TOUCH 1 sbase\-VERSION
|
.TH TOUCH 1 sbase\-VERSION
|
||||||
.SH NAME
|
.SH NAME
|
||||||
touch \- set files' modification time
|
touch \- set files' timestamps
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B touch
|
.B touch
|
||||||
.RB [ \-c ]
|
.RB [ \-c ]
|
||||||
|
@ -9,8 +9,8 @@ touch \- set files' modification time
|
||||||
.RI [ file ...]
|
.RI [ file ...]
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
.B touch
|
.B touch
|
||||||
sets the files' modification time to the current time. If a file does not exist
|
sets the given files' modification time to the current time. If a file does not
|
||||||
it is created.
|
exist it is created.
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
.TP
|
.TP
|
||||||
.B \-c
|
.B \-c
|
||||||
|
|
Loading…
Reference in New Issue
Block a user