Remove debugging statement.
[oweals/busybox.git] / mkdir.c
diff --git a/mkdir.c b/mkdir.c
index 8f1fa04db50d705f93a888e6db2deb99a6314a80..03c49f0983cfa96486cc3d09c5c35c3619a112a1 100644 (file)
--- a/mkdir.c
+++ b/mkdir.c
@@ -1,58 +1,64 @@
-#include "internal.h"
+/* vi: set sw=4 ts=4: */
+/*
+ * Mini mkdir implementation for busybox
+ *
+ * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
 #include <errno.h>
-#include <sys/param.h>
+#include <getopt.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
 
-const char mkdir_usage[] = "mkdir [-m mode] directory [directory ...]\n"
-"\tCreate directories.\n"
-"\n"
-"\t-m mode:\tSpecifiy the mode for the new directory\n"
-"\t\tunder the argument directory.";
+#include "busybox.h"
 
-/*make directories skipping the last part of the path. Used here and by untar*/
-int mkdir_until(const char *fpath, const struct FileInfo * fi)
+extern int mkdir_main (int argc, char **argv)
 {
-       char    path[PATH_MAX];
-       char *  s = path;
-
-       strcpy(path, fpath);
-       if ( s[0] == '\0' && s[1] == '\0' ) {
-               usage(mkdir_usage);
-               return 1;
-       }
-       s++;
-       while ( *s != '\0' ) {
-               if ( *s == '/' ) {
-                       int     status;
-
-                       *s = '\0';
-                       status = mkdir(path, (fi?fi->orWithMode:0700) );
-                       *s = '/';
-
-                       if ( status != 0 ) {
-                               if ( errno != EEXIST ) {
-                                       name_and_error(fpath);
-                                       return 1;
-                               }
-                       }
+       mode_t mode = -1;
+       int flags = 0;
+       int status = 0;
+       int i, opt;
 
+       while ((opt = getopt (argc, argv, "m:p")) != -1) {
+               switch (opt) {
+               case 'm':
+                       mode = 0777;
+                       if (!parse_mode (optarg, &mode))
+                               error_msg_and_die ("invalid mode `%s'", optarg);
+                       break;
+               case 'p':
+                       flags |= FILEUTILS_RECUR;
+                       break;
+               default:
+                       show_usage ();
                }
-               s++;
        }
-       return 0;
-}
 
-int
-mkdir_fn(const struct FileInfo * i)
-{
-       if ( i->makeParentDirectories ) {
-               if(mkdir_until(i->source, i)) return 1;
-       }
+       if (optind == argc)
+               show_usage ();
 
-       if ( mkdir(i->source, i->orWithMode) != 0 && errno != EEXIST ) {
-               name_and_error(i->source);
-               return 1;
-       }
-       else
-               return 0;
-}
+       for (i = optind; i < argc; i++)
+               if (make_directory (argv[i], mode, flags) < 0)
+                       status = 1;
 
+       return status;
+}