don't whine if all we need to do is remove a bg job
[oweals/busybox.git] / mkdir.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Mini mkdir implementation for busybox
4  *
5  * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  */
22
23 #include <errno.h>
24 #include <getopt.h>
25 #include <sys/stat.h>
26 #include <sys/types.h>
27 #include <fcntl.h>
28 #include <unistd.h>
29 #include <stdlib.h>
30 #include <string.h>
31
32 #include "busybox.h"
33
34 extern int mkdir_main (int argc, char **argv)
35 {
36         mode_t mode = -1;
37         int flags = 0;
38         int status = 0;
39         int i, opt;
40
41         while ((opt = getopt (argc, argv, "m:p")) != -1) {
42                 switch (opt) {
43                 case 'm':
44                         mode = 0777;
45                         if (!parse_mode (optarg, &mode))
46                                 error_msg_and_die ("invalid mode `%s'", optarg);
47                         break;
48                 case 'p':
49                         flags |= FILEUTILS_RECUR;
50                         break;
51                 default:
52                         show_usage ();
53                 }
54         }
55
56         if (optind == argc)
57                 show_usage ();
58
59         for (i = optind; i < argc; i++)
60                 if (make_directory (argv[i], mode, flags) < 0)
61                         status = 1;
62
63         return status;
64 }