Files
applets
arch
archival
console-tools
coreutils
libcoreutils
Config.in
Kbuild
basename.c
cal.c
cat.c
catv.c
chgrp.c
chmod.c
chown.c
chroot.c
cksum.c
comm.c
cp.c
cut.c
date.c
dd.c
df.c
dirname.c
dos2unix.c
du.c
echo.c
env.c
expand.c
expr.c
false.c
fold.c
head.c
hostid.c
id.c
install.c
length.c
ln.c
logname.c
ls.c
md5_sha1_sum.c
mkdir.c
mkfifo.c
mknod.c
mv.c
nice.c
nohup.c
od.c
od_bloaty.c
printenv.c
printf.c
pwd.c
readlink.c
realpath.c
rm.c
rmdir.c
seq.c
sleep.c
sort.c
split.c
stat.c
stty.c
sum.c
sync.c
tac.c
tail.c
tee.c
test.c
touch.c
tr.c
true.c
tty.c
uname.c
uniq.c
usleep.c
uudecode.c
uuencode.c
wc.c
who.c
whoami.c
yes.c
debianutils
docs
e2fsprogs
editors
examples
findutils
include
init
ipsvd
libbb
libpwdgrp
loginutils
miscutils
modutils
networking
printutils
procps
runit
scripts
selinux
shell
sysklogd
testsuite
util-linux
.indent.pro
AUTHORS
Config.in
INSTALL
LICENSE
Makefile
Makefile.custom
Makefile.flags
Makefile.help
README
TODO
TODO_config_nommu
busybox/coreutils/mkdir.c
Denis Vlasenko 9b49a5ed85 add -fvisibility=hidden to CC flags, mark XXX_main functions
EXTERNALLY_VISIBLE. 5% size reduction of libbusybox.so
2007-10-11 10:05:36 +00:00

82 lines
1.8 KiB
C

/* vi: set sw=4 ts=4: */
/*
* Mini mkdir implementation for busybox
*
* Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/mkdir.html */
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
*
* Fixed broken permission setting when -p was used; especially in
* conjunction with -m.
*/
/* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support.
*/
#include <getopt.h> /* struct option */
#include "libbb.h"
/* This is a NOFORK applet. Be very careful! */
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
static const char mkdir_longopts[] ALIGN1 =
"mode\0" Required_argument "m"
"parents\0" No_argument "p"
#if ENABLE_SELINUX
"context\0" Required_argument "Z"
#endif
;
#endif
int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int mkdir_main(int argc, char **argv)
{
mode_t mode = (mode_t)(-1);
int status = EXIT_SUCCESS;
int flags = 0;
unsigned opt;
char *smode;
#if ENABLE_SELINUX
security_context_t scontext;
#endif
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
applet_long_options = mkdir_longopts;
#endif
opt = getopt32(argv, "m:p" USE_SELINUX("Z:"), &smode USE_SELINUX(,&scontext));
if (opt & 1) {
mode = 0777;
if (!bb_parse_mode(smode, &mode)) {
bb_error_msg_and_die("invalid mode '%s'", smode);
}
}
if (opt & 2)
flags |= FILEUTILS_RECUR;
#if ENABLE_SELINUX
if (opt & 4) {
selinux_or_die();
setfscreatecon_or_die(scontext);
}
#endif
if (optind == argc) {
bb_show_usage();
}
argv += optind;
do {
if (bb_make_directory(*argv, mode, flags)) {
status = EXIT_FAILURE;
}
} while (*++argv);
return status;
}