blob: f003db99fa25d606f2b83ab11168815e02f7f74a [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;
Matt Kraaiceeff732001-06-21 19:41:37 +000038 int i, opt;
Eric Andersencc8ed391999-10-05 16:24:54 +000039
Matt Kraaiceeff732001-06-21 19:41:37 +000040 while ((opt = getopt (argc, argv, "m:p")) != -1) {
41 switch (opt) {
42 case 'm':
43 mode = 0777;
Glenn L McGrath822e7fd2002-11-24 22:48:20 +000044 if (!parse_mode (optarg, &mode)) {
Matt Kraaiceeff732001-06-21 19:41:37 +000045 error_msg_and_die ("invalid mode `%s'", optarg);
Glenn L McGrath822e7fd2002-11-24 22:48:20 +000046 }
47 umask(0);
Matt Kraaiceeff732001-06-21 19:41:37 +000048 break;
49 case 'p':
50 flags |= FILEUTILS_RECUR;
51 break;
52 default:
53 show_usage ();
Eric Andersenfa0540f1999-10-22 18:18:31 +000054 }
Eric Andersenfa0540f1999-10-22 18:18:31 +000055 }
Eric Andersenf6be9441999-10-13 21:12:06 +000056
Matt Kraaiceeff732001-06-21 19:41:37 +000057 if (optind == argc)
58 show_usage ();
Eric Andersenf6be9441999-10-13 21:12:06 +000059
Glenn L McGrath924f93e2002-09-28 08:32:14 +000060 for (i = optind; i < argc; i++) {
61 make_directory (argv[i], mode, flags);
62 }
Erik Andersene49d5ec2000-02-08 19:58:47 +000063
Glenn L McGrath924f93e2002-09-28 08:32:14 +000064 return(EXIT_SUCCESS);
Eric Andersencc8ed391999-10-05 16:24:54 +000065}