blob: 03c49f0983cfa96486cc3d09c5c35c3619a112a1 [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersenf6be9441999-10-13 21:12:06 +00002/*
3 * Mini mkdir implementation for busybox
4 *
Matt Kraaiceeff732001-06-21 19:41:37 +00005 * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
Eric Andersenf6be9441999-10-13 21:12:06 +00006 *
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
Eric Andersencbe31da2001-02-20 06:14:08 +000023#include <errno.h>
Matt Kraaiceeff732001-06-21 19:41:37 +000024#include <getopt.h>
25#include <sys/stat.h>
26#include <sys/types.h>
27#include <fcntl.h>
28#include <unistd.h>
Eric Andersencbe31da2001-02-20 06:14:08 +000029#include <stdlib.h>
Matt Kraaiceeff732001-06-21 19:41:37 +000030#include <string.h>
31
Eric Andersen3570a342000-09-25 21:45:58 +000032#include "busybox.h"
Erik Andersenfac10d72000-02-07 05:29:42 +000033
Matt Kraaiceeff732001-06-21 19:41:37 +000034extern int mkdir_main (int argc, char **argv)
Eric Andersencc8ed391999-10-05 16:24:54 +000035{
Matt Kraaiceeff732001-06-21 19:41:37 +000036 mode_t mode = -1;
37 int flags = 0;
38 int status = 0;
39 int i, opt;
Eric Andersencc8ed391999-10-05 16:24:54 +000040
Matt Kraaiceeff732001-06-21 19:41:37 +000041 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 ();
Eric Andersenfa0540f1999-10-22 18:18:31 +000053 }
Eric Andersenfa0540f1999-10-22 18:18:31 +000054 }
Eric Andersenf6be9441999-10-13 21:12:06 +000055
Matt Kraaiceeff732001-06-21 19:41:37 +000056 if (optind == argc)
57 show_usage ();
Eric Andersenf6be9441999-10-13 21:12:06 +000058
Matt Kraaiceeff732001-06-21 19:41:37 +000059 for (i = optind; i < argc; i++)
60 if (make_directory (argv[i], mode, flags) < 0)
61 status = 1;
Erik Andersene49d5ec2000-02-08 19:58:47 +000062
Matt Kraaiceeff732001-06-21 19:41:37 +000063 return status;
Eric Andersencc8ed391999-10-05 16:24:54 +000064}