diff options
author | Rob Landley <rob@landley.net> | 2012-11-13 17:14:08 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2012-11-13 17:14:08 -0600 |
commit | 7aa651a6a4496d848f86de9b1e6b3a003256a01f (patch) | |
tree | 6995fb4b7cc2e90a6706b0239ebaf95d9dbab530 /toys/posix/mkdir.c | |
parent | 571b0706cce45716126776d0ad0f6ac65f4586e3 (diff) | |
download | toybox-7aa651a6a4496d848f86de9b1e6b3a003256a01f.tar.gz |
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
The actual code should be the same afterward, this is just cosmetic refactoring.
Diffstat (limited to 'toys/posix/mkdir.c')
-rw-r--r-- | toys/posix/mkdir.c | 78 |
1 files changed, 38 insertions, 40 deletions
diff --git a/toys/posix/mkdir.c b/toys/posix/mkdir.c index e4e591d7..33fb8326 100644 --- a/toys/posix/mkdir.c +++ b/toys/posix/mkdir.c @@ -1,6 +1,4 @@ -/* vi: set sw=4 ts=4: - * - * mkdir.c - Make directories +/* mkdir.c - Make directories * * Copyright 2012 Georgi Chorbadzhiyski <georgi@unixsol.org> * @@ -11,65 +9,65 @@ USE_MKDIR(NEWTOY(mkdir, "<1p", TOYFLAG_BIN)) config MKDIR - bool "mkdir" - default y - help - usage: mkdir [-p] [dirname...] - Create one or more directories. + bool "mkdir" + default y + help + usage: mkdir [-p] [dirname...] + Create one or more directories. - -p make parent directories as needed. + -p make parent directories as needed. */ #define FOR_mkdir #include "toys.h" GLOBALS( - long mode; + long mode; ) static int do_mkdir(char *dir) { - struct stat buf; - char *s; + struct stat buf; + char *s; - // mkdir -p one/two/three is not an error if the path already exists, - // but is if "three" is a file. The others we dereference and catch - // not-a-directory along the way, but the last one we must explicitly - // test for. Might as well do it up front. + // mkdir -p one/two/three is not an error if the path already exists, + // but is if "three" is a file. The others we dereference and catch + // not-a-directory along the way, but the last one we must explicitly + // test for. Might as well do it up front. - if (!stat(dir, &buf) && !S_ISDIR(buf.st_mode)) { - errno = EEXIST; - return 1; - } + if (!stat(dir, &buf) && !S_ISDIR(buf.st_mode)) { + errno = EEXIST; + return 1; + } - for (s=dir; ; s++) { - char save=0; + for (s=dir; ; s++) { + char save=0; - // Skip leading / of absolute paths. - if (s!=dir && *s == '/' && toys.optflags) { - save = *s; - *s = 0; - } else if (*s) continue; + // Skip leading / of absolute paths. + if (s!=dir && *s == '/' && toys.optflags) { + save = *s; + *s = 0; + } else if (*s) continue; - if (mkdir(dir, TT.mode)<0 && (!toys.optflags || errno != EEXIST)) - return 1; + if (mkdir(dir, TT.mode)<0 && (!toys.optflags || errno != EEXIST)) + return 1; - if (!(*s = save)) break; - } + if (!(*s = save)) break; + } - return 0; + return 0; } void mkdir_main(void) { - char **s; + char **s; - TT.mode = 0777; + TT.mode = 0777; - for (s=toys.optargs; *s; s++) { - if (do_mkdir(*s)) { - perror_msg("cannot create directory '%s'", *s); - toys.exitval = 1; - } - } + for (s=toys.optargs; *s; s++) { + if (do_mkdir(*s)) { + perror_msg("cannot create directory '%s'", *s); + toys.exitval = 1; + } + } } |