Author | Jamozed <[email protected]> |
Date | 2020-07-06 10:52:45 |
Commit | 76371b717ade76542fd0be74fd725b8518493bab |
Parent | c6fc8c9a81736e36f26b79436c1b63c8886b432f |
mkdir: Use libokv error reporting
Diffstat
M | src/mkdir.c | | | 37 | ++++++++++++++++--------------------- |
1 files changed, 16 insertions, 21 deletions
diff --git a/src/mkdir.c b/src/mkdir.c index 04a145d..d58ea7a 100644 --- a/src/mkdir.c +++ b/src/mkdir.c @@ -1,4 +1,4 @@ -// mkdir.c, version 1.0.1 +// mkdir.c, version 1.0.2 // OMKOV coreutils implementation of POSIX mkdir // Copyright (C) 2020, Jakob Wakeling // All rights reserved. @@ -33,16 +33,18 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. */ -#include "error.h" #include "optget.h" +#include <error.h> + #include <sys/stat.h> #include <ctype.h> #include <errno.h> #include <stdbool.h> #include <stdio.h> -#include <string.h> + +#define VERSION "1.0.2" #define USR 05700 #define GRP 02070 @@ -69,7 +71,7 @@ static inline mode_t getmod(char **mstr); static void help(void); static void version(void); -int main(int argc, char *argv[]) { +int main(int ac, char *av[]) { A0 = av[0]; lop_t lops[] = { { "help", ARG_NUL, 256 }, { "version", ARG_NUL, 257 }, @@ -77,7 +79,7 @@ int main(int argc, char *argv[]) { }; opt_t opt = OPTGET_INIT; opt.str = "m:p"; opt.lops = lops; int o; - while ((o = optget(&opt, argv, 1)) != -1) switch (o) { + while ((o = optget(&opt, av, 1)) != -1) switch (o) { case 'm': { mopt = opt.arg; break; } case 'p': { pflag = true; break; } case 256: { help(); return 0; } @@ -85,33 +87,26 @@ int main(int argc, char *argv[]) { default: { return 1; } } - if (opt.ind == argc) { error(1, "%s: missing operand", argv[0]); } + if (opt.ind == ac) { error(1, "missing operand"); } if (mopt) { mask = umask(0); mode = newmode(mopt); - if (mode == (mode_t)-1) { - error(1, "%s: %s: invalid mode", argv[0], mopt); - } + if (mode == (mode_t)-1) { error(1, "%s: invalid mode", mopt); } } else { mode = 0777; } - for (int i = opt.ind; i < argc; ++i) { + for (int i = opt.ind; i < ac; ++i) { if (pflag) { - char *p = argv[i]; + char *p = av[i]; for (; *p == '/'; ++p) {} for (; *p; ++p) { if (*p != '/' || *(p + 1) == '/') { continue; } *p = 0; - if (mkdir(argv[i], mode)) { - if (errno != EEXIST) { - warn("%s: %s: %s", argv[0], argv[i], serrno); continue; - } - } - *p = '/'; + if (mkdir(av[i], mode)) if (errno != EEXIST) { + warn("%s: %s", av[i], serr()); continue; + } *p = '/'; } } - if (mkdir(argv[i], mode)) { - warn("%s: %s: %s", argv[0], argv[i], serrno); continue; - } + if (mkdir(av[i], mode)) { warn("%s: %s", av[i], serr()); continue; } } return 0; @@ -199,7 +194,7 @@ static void help(void) { } static void version(void) { - puts("OMKOV coreutils mkdir, version 1.0.1"); + puts("OMKOV coreutils mkdir, version " VERSION); puts("Copyright (C) 2020, Jakob Wakeling"); puts("All rights reserved."); puts("OMKOV Permissive Licence (https://www.omkov.net/OLPE)");