2011-05-26 04:47:58 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2015-02-14 20:02:41 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2011-05-26 04:47:58 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
2014-11-13 17:29:30 +00:00
|
|
|
|
2011-05-26 04:47:58 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2013-06-14 18:20:47 +00:00
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2015-03-05 17:03:08 +00:00
|
|
|
eprintf("usage: %s [-p] [-m mode] name ...\n", argv0);
|
2013-06-14 18:20:47 +00:00
|
|
|
}
|
|
|
|
|
2011-05-26 04:47:58 +00:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2015-03-05 17:03:08 +00:00
|
|
|
mode_t mode = 0, mask;
|
|
|
|
int pflag = 0, mflag = 0, ret = 0;
|
2013-06-14 18:20:47 +00:00
|
|
|
|
|
|
|
ARGBEGIN {
|
|
|
|
case 'p':
|
2014-11-13 20:24:47 +00:00
|
|
|
pflag = 1;
|
2013-06-14 18:20:47 +00:00
|
|
|
break;
|
2013-08-31 21:51:25 +00:00
|
|
|
case 'm':
|
2014-11-13 20:24:47 +00:00
|
|
|
mflag = 1;
|
2015-01-28 19:57:32 +00:00
|
|
|
mask = getumask();
|
|
|
|
mode = parsemode(EARGF(usage()), mode, mask);
|
2013-08-31 21:51:25 +00:00
|
|
|
break;
|
2013-06-14 18:20:47 +00:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
2015-03-05 17:03:08 +00:00
|
|
|
if (!argc)
|
2013-08-31 22:04:49 +00:00
|
|
|
usage();
|
|
|
|
|
2015-03-05 17:03:08 +00:00
|
|
|
for (; *argv; argc--, argv++) {
|
2015-04-20 15:12:36 +00:00
|
|
|
if (pflag) {
|
|
|
|
if (mkdirp(*argv) < 0)
|
|
|
|
ret = 1;
|
|
|
|
} else if (mkdir(*argv, S_IRWXU | S_IRWXG | S_IRWXO) < 0 &&
|
|
|
|
errno != EEXIST) {
|
2015-03-13 11:15:30 +00:00
|
|
|
weprintf("mkdir %s:", *argv);
|
|
|
|
ret = 1;
|
2015-04-20 15:12:36 +00:00
|
|
|
}
|
|
|
|
if (mflag && chmod(*argv, mode) < 0) {
|
2015-03-05 17:03:08 +00:00
|
|
|
weprintf("chmod %s:", *argv);
|
2015-01-28 19:57:32 +00:00
|
|
|
ret = 1;
|
2011-05-26 04:47:58 +00:00
|
|
|
}
|
2013-06-14 18:20:47 +00:00
|
|
|
}
|
2015-03-05 17:03:08 +00:00
|
|
|
|
2015-01-28 19:57:32 +00:00
|
|
|
return ret;
|
2011-05-26 04:47:58 +00:00
|
|
|
}
|