aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/mkdir.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2014-11-17 11:21:06 -0500
committerRuss Cox <rsc@swtch.com>2014-11-17 11:21:06 -0500
commitc9ed52730b352448c7c644f6942d310dd3509bf6 (patch)
treed9723cd78c8b632e76e90f51ae43bd65c2139116 /src/cmd/mkdir.c
parent08e793723cad1c7aed2e8cb16c8592aba5ad05e9 (diff)
downloadplan9port-c9ed52730b352448c7c644f6942d310dd3509bf6.tar.gz
plan9port-c9ed52730b352448c7c644f6942d310dd3509bf6.tar.bz2
plan9port-c9ed52730b352448c7c644f6942d310dd3509bf6.zip
cmd: rename *.C to *.c
These were *.C back in 2003, before the 9 script, to avoid conflicts with the system utilities. A later change renamed them, but that change seems to have been lost during the hg->git conversion because I ran the conversion on a case-insensitive file system. Change-Id: Id32c99cb9571ef0e185c3cc9e8c8d6d5b48ca195
Diffstat (limited to 'src/cmd/mkdir.c')
-rw-r--r--src/cmd/mkdir.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/cmd/mkdir.c b/src/cmd/mkdir.c
new file mode 100644
index 00000000..1c16565d
--- /dev/null
+++ b/src/cmd/mkdir.c
@@ -0,0 +1,80 @@
+#include <u.h>
+#include <libc.h>
+
+char *e;
+ulong mode = 0777L;
+
+void
+usage(void)
+{
+ fprint(2, "usage: mkdir [-p] [-m mode] dir...\n");
+ exits("usage");
+}
+
+int
+makedir(char *s)
+{
+ int f;
+
+ if(access(s, AEXIST) == 0){
+ fprint(2, "mkdir: %s already exists\n", s);
+ e = "error";
+ return -1;
+ }
+ f = create(s, OREAD, DMDIR | mode);
+ if(f < 0){
+ fprint(2, "mkdir: can't create %s: %r\n", s);
+ e = "error";
+ return -1;
+ }
+ close(f);
+ return 0;
+}
+
+void
+mkdirp(char *s)
+{
+ char *p;
+
+ for(p=strchr(s+1, '/'); p; p=strchr(p+1, '/')){
+ *p = 0;
+ if(access(s, AEXIST) != 0 && makedir(s) < 0)
+ return;
+ *p = '/';
+ }
+ if(access(s, AEXIST) != 0)
+ makedir(s);
+}
+
+
+void
+main(int argc, char *argv[])
+{
+ int i, pflag;
+ char *m;
+
+ pflag = 0;
+ ARGBEGIN{
+ default:
+ usage();
+ case 'm':
+ m = ARGF();
+ if(m == nil)
+ usage();
+ mode = strtoul(m, &m, 8);
+ if(mode > 0777)
+ usage();
+ break;
+ case 'p':
+ pflag = 1;
+ break;
+ }ARGEND
+
+ for(i=0; i<argc; i++){
+ if(pflag)
+ mkdirp(argv[i]);
+ else
+ makedir(argv[i]);
+ }
+ exits(e);
+}