aboutsummaryrefslogtreecommitdiff
path: root/coreutils/mkdir.c
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-02-07 05:29:42 +0000
committerErik Andersen <andersen@codepoet.org>2000-02-07 05:29:42 +0000
commitfac10d7c59f7db0facd5fb94de273310b9ec86e6 (patch)
treedccf8f905fc5807239883da9fca6597037d487fc /coreutils/mkdir.c
parent50bc101b7d6e847a9a0621ca3eb28c7117d095e5 (diff)
downloadbusybox-w32-fac10d7c59f7db0facd5fb94de273310b9ec86e6.tar.gz
busybox-w32-fac10d7c59f7db0facd5fb94de273310b9ec86e6.tar.bz2
busybox-w32-fac10d7c59f7db0facd5fb94de273310b9ec86e6.zip
A few minor updates. ;-)
Seriously though, read the Changelog for busybox 0.42, which this is about to become... -Erik
Diffstat (limited to 'coreutils/mkdir.c')
-rw-r--r--coreutils/mkdir.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c
index 017ef9b08..8e3f51bfb 100644
--- a/coreutils/mkdir.c
+++ b/coreutils/mkdir.c
@@ -22,9 +22,13 @@
22 */ 22 */
23 23
24#include "internal.h" 24#include "internal.h"
25#define bb_need_name_too_long
26#define BB_DECLARE_EXTERN
27#include "messages.c"
28
25#include <stdio.h> 29#include <stdio.h>
26#include <errno.h> 30#include <errno.h>
27#include <sys/param.h> 31#include <sys/param.h> /* for PATH_MAX */
28 32
29static const char mkdir_usage[] = 33static const char mkdir_usage[] =
30"mkdir [OPTION] DIRECTORY...\n\n" 34"mkdir [OPTION] DIRECTORY...\n\n"
@@ -40,27 +44,27 @@ static mode_t mode = 0777;
40 44
41extern int mkdir_main(int argc, char **argv) 45extern int mkdir_main(int argc, char **argv)
42{ 46{
43 int i=FALSE; 47 int i = FALSE;
44 argc--; 48 argc--;
45 argv++; 49 argv++;
46 50
47 /* Parse any options */ 51 /* Parse any options */
48 while (argc > 0 && **argv == '-') { 52 while (argc > 0 && **argv == '-') {
49 while (i==FALSE && *++(*argv)) { 53 while (i == FALSE && *++(*argv)) {
50 switch (**argv) { 54 switch (**argv) {
51 case 'm': 55 case 'm':
52 if (--argc == 0) 56 if (--argc == 0)
53 usage( mkdir_usage); 57 usage( mkdir_usage);
54 /* Find the specified modes */ 58 /* Find the specified modes */
55 mode = 0; 59 mode = 0;
56 if ( parse_mode(*(++argv), &mode) == FALSE ) { 60 if (parse_mode(*(++argv), &mode) == FALSE ) {
57 fprintf(stderr, "Unknown mode: %s\n", *argv); 61 fprintf(stderr, "Unknown mode: %s\n", *argv);
58 exit( FALSE); 62 exit FALSE;
59 } 63 }
60 /* Set the umask for this process so it doesn't 64 /* Set the umask for this process so it doesn't
61 * screw up whatever the user just entered. */ 65 * screw up whatever the user just entered. */
62 umask(0); 66 umask(0);
63 i=TRUE; 67 i = TRUE;
64 break; 68 break;
65 case 'p': 69 case 'p':
66 parentFlag = TRUE; 70 parentFlag = TRUE;
@@ -73,7 +77,6 @@ extern int mkdir_main(int argc, char **argv)
73 argv++; 77 argv++;
74 } 78 }
75 79
76
77 if (argc < 1) { 80 if (argc < 1) {
78 usage( mkdir_usage); 81 usage( mkdir_usage);
79 } 82 }
@@ -81,13 +84,16 @@ extern int mkdir_main(int argc, char **argv)
81 while (argc > 0) { 84 while (argc > 0) {
82 int status; 85 int status;
83 struct stat statBuf; 86 struct stat statBuf;
84 char buf[NAME_MAX]; 87 char buf[PATH_MAX + 1];
85 88 if (strlen(*argv) > PATH_MAX - 1) {
89 fprintf(stderr, name_too_long, "mkdir");
90 exit FALSE;
91 }
86 strcpy (buf, *argv); 92 strcpy (buf, *argv);
87 status=stat(buf, &statBuf); 93 status = stat(buf, &statBuf);
88 if (parentFlag == FALSE && status != -1 && status != ENOENT ) { 94 if (parentFlag == FALSE && status != -1 && errno != ENOENT) {
89 fprintf(stderr, "%s: File exists\n", buf); 95 fprintf(stderr, "%s: File exists\n", buf);
90 exit( FALSE); 96 exit FALSE;
91 } 97 }
92 if (parentFlag == TRUE) { 98 if (parentFlag == TRUE) {
93 strcat( buf, "/"); 99 strcat( buf, "/");
@@ -96,13 +102,13 @@ extern int mkdir_main(int argc, char **argv)
96 else { 102 else {
97 if (mkdir (buf, mode) != 0 && parentFlag == FALSE) { 103 if (mkdir (buf, mode) != 0 && parentFlag == FALSE) {
98 perror(buf); 104 perror(buf);
99 exit( FALSE); 105 exit FALSE;
100 } 106 }
101 } 107 }
102 argc--; 108 argc--;
103 argv++; 109 argv++;
104 } 110 }
105 exit( TRUE); 111 exit TRUE;
106} 112}
107 113
108 114