aboutsummaryrefslogtreecommitdiff
path: root/coreutils/mkdir.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-13 21:12:06 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-13 21:12:06 +0000
commitf6be944a6ae612c70ce010582d9c3cdd72f7144f (patch)
tree36ab89d86aad17d6922566cad8e49ba33c5ede81 /coreutils/mkdir.c
parent305a73f5eacd94eefe2f2a5a00034d579ef6b1e7 (diff)
downloadbusybox-w32-f6be944a6ae612c70ce010582d9c3cdd72f7144f.tar.gz
busybox-w32-f6be944a6ae612c70ce010582d9c3cdd72f7144f.tar.bz2
busybox-w32-f6be944a6ae612c70ce010582d9c3cdd72f7144f.zip
More stuff
Diffstat (limited to 'coreutils/mkdir.c')
-rw-r--r--coreutils/mkdir.c119
1 files changed, 73 insertions, 46 deletions
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c
index 8f1fa04db..61d35d5cd 100644
--- a/coreutils/mkdir.c
+++ b/coreutils/mkdir.c
@@ -1,58 +1,85 @@
1/*
2 * Mini mkdir implementation for busybox
3 *
4 * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
1#include "internal.h" 22#include "internal.h"
23#include <stdio.h>
2#include <errno.h> 24#include <errno.h>
3#include <sys/param.h> 25#include <sys/param.h>
4 26
5const char mkdir_usage[] = "mkdir [-m mode] directory [directory ...]\n" 27const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n"
6"\tCreate directories.\n" 28"Create the DIRECTORY(ies), if they do not already exist\n\n"
7"\n" 29"-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
8"\t-m mode:\tSpecifiy the mode for the new directory\n" 30"-p\tno error if existing, make parent directories as needed\n";
9"\t\tunder the argument directory.";
10 31
11/*make directories skipping the last part of the path. Used here and by untar*/
12int mkdir_until(const char *fpath, const struct FileInfo * fi)
13{
14 char path[PATH_MAX];
15 char * s = path;
16 32
17 strcpy(path, fpath); 33static int parentFlag = FALSE;
18 if ( s[0] == '\0' && s[1] == '\0' ) { 34static int permFlag = FALSE;
19 usage(mkdir_usage); 35static mode_t mode = 0777;
20 return 1; 36
21 }
22 s++;
23 while ( *s != '\0' ) {
24 if ( *s == '/' ) {
25 int status;
26
27 *s = '\0';
28 status = mkdir(path, (fi?fi->orWithMode:0700) );
29 *s = '/';
30
31 if ( status != 0 ) {
32 if ( errno != EEXIST ) {
33 name_and_error(fpath);
34 return 1;
35 }
36 }
37
38 }
39 s++;
40 }
41 return 0;
42}
43 37
44int 38extern int mkdir_main(int argc, char **argv)
45mkdir_fn(const struct FileInfo * i)
46{ 39{
47 if ( i->makeParentDirectories ) { 40 argc--;
48 if(mkdir_until(i->source, i)) return 1; 41 argv++;
49 } 42
43 /* Parse any options */
44 while (argc > 1 && **argv == '-') {
45 while (*++(*argv))
46 switch (**argv) {
47 case 'm':
48 permFlag = TRUE;
49 break;
50 case 'p':
51 parentFlag = TRUE;
52 break;
53 default:
54 fprintf(stderr, "%s\n", mkdir_usage);
55 exit(FALSE);
56 }
57 argc--;
58 argv++;
59 }
60
50 61
51 if ( mkdir(i->source, i->orWithMode) != 0 && errno != EEXIST ) { 62 if (argc < 1) {
52 name_and_error(i->source); 63 fprintf(stderr, "%s\n", mkdir_usage);
53 return 1; 64 exit (FALSE);
65 }
66
67 while (--argc > 0) {
68 struct stat statBuf;
69 if (stat(*(++argv), &statBuf) != ENOENT) {
70 fprintf(stderr, "%s: File exists\n", *argv);
71 return( FALSE);
72 }
73 if (parentFlag == TRUE)
74 createPath(*argv, mode);
75 else {
76 if (mkdir (*argv, mode) != 0) {
77 perror(*argv);
78 exit( FALSE);
79 }
54 } 80 }
55 else 81 }
56 return 0; 82 exit( TRUE);
57} 83}
58 84
85