aboutsummaryrefslogtreecommitdiff
path: root/coreutils/mkdir.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-05 16:24:54 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-05 16:24:54 +0000
commitcc8ed39b240180b58810784f844e253263594ac3 (patch)
tree15feebbb4be9a9168209609f48f0b100f9364420 /coreutils/mkdir.c
downloadbusybox-cc8ed39b240180b58810784f844e253263594ac3.tar.gz
Initial revision
Diffstat (limited to 'coreutils/mkdir.c')
-rw-r--r--coreutils/mkdir.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c
new file mode 100644
index 000000000..8f1fa04db
--- /dev/null
+++ b/coreutils/mkdir.c
@@ -0,0 +1,58 @@
+#include "internal.h"
+#include <errno.h>
+#include <sys/param.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.";
+
+/*make directories skipping the last part of the path. Used here and by untar*/
+int mkdir_until(const char *fpath, const struct FileInfo * fi)
+{
+ 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;
+ }
+ }
+
+ }
+ s++;
+ }
+ return 0;
+}
+
+int
+mkdir_fn(const struct FileInfo * i)
+{
+ if ( i->makeParentDirectories ) {
+ if(mkdir_until(i->source, i)) return 1;
+ }
+
+ if ( mkdir(i->source, i->orWithMode) != 0 && errno != EEXIST ) {
+ name_and_error(i->source);
+ return 1;
+ }
+ else
+ return 0;
+}
+