diff options
-rw-r--r-- | src/shh-portable-utils/chmod.c | 11 | ||||
-rw-r--r-- | src/shh-portable-utils/parse_mode_symbolic.c | 49 |
2 files changed, 40 insertions, 20 deletions
diff --git a/src/shh-portable-utils/chmod.c b/src/shh-portable-utils/chmod.c index 51a41fe..48a2305 100644 --- a/src/shh-portable-utils/chmod.c +++ b/src/shh-portable-utils/chmod.c @@ -56,11 +56,12 @@ int main(int argc, char const *const *argv) if (parse_mode_octal(argv[0], &mode)) strerr_dief2sys(100, "invalid mode: ", argv[0]); } else { - int result = parse_mode_symbolic(argv[0], &directives); - if (result == 1) - strerr_dief2x(100, "invalid mode: ", argv[0]); - else if (result == 2) - strerr_diefu1sys(111, "parse mode"); + if (parse_mode_symbolic(argv[0], &directives) == -1) { + if (errno == EINVAL) + strerr_diefu2sys(100, "invalid mode: ", argv[0]); + else + strerr_diefu1sys(111, "parse mode") + } if (!genalloc_len(chmod_directive, &directives)) strerr_dieusage(100, USAGE); } diff --git a/src/shh-portable-utils/parse_mode_symbolic.c b/src/shh-portable-utils/parse_mode_symbolic.c index 536757d..96cb94a 100644 --- a/src/shh-portable-utils/parse_mode_symbolic.c +++ b/src/shh-portable-utils/parse_mode_symbolic.c @@ -1,3 +1,5 @@ +#include <errno.h> + #include <skalibs/genalloc.h> #include <skalibs/strerr2.h> @@ -30,7 +32,8 @@ int parse_mode_symbolic(char const *raw, genalloc *directives) d.action = *p; break; default: - return 1; + errno = EINVAL; + return -1; } p++; for (;;) { @@ -56,19 +59,26 @@ int parse_mode_symbolic(char const *raw, genalloc *directives) break; } else if (*p == '\0') { - if (d.perm && d.permcopy) - return 1; + if (d.perm && d.permcopy) { + errno = EINVAL; + return -1; + } if (!genalloc_append(chmod_directive, directives, &d)) - return 2; + return -1; /* errno = ENOMEM */ return 0; + } else { + errno = EINVAL; + return -1; } p++; } - if (d.perm && d.permcopy) - return 1; + if (d.perm && d.permcopy) { + errno = EINVAL; + return -1; + } if (!genalloc_append(chmod_directive, directives, &d)) - return 2; + return -1; /* errno = ENOMEM */ for (;;) { d.action = d.perm = d.permcopy = d.dir_x = 0; @@ -80,8 +90,10 @@ int parse_mode_symbolic(char const *raw, genalloc *directives) } else if (*p == '\0') return 0; - else - return 1; + else { + errno = EIVAL; + return -1; + } p++; @@ -109,19 +121,26 @@ int parse_mode_symbolic(char const *raw, genalloc *directives) break; } else if (*p == '\0') { - if (d.perm && d.permcopy) - return 1; + if (d.perm && d.permcopy) { + errno = EINVAL; + return -1; + } if (!genalloc_append(chmod_directive, directives, &d)) - return 2; + return -1; /* errno = ENOMEM */ return 0; + } else { + errno = EINVAL; + return -1; } p++; } - if (d.perm && d.permcopy) - return 1; + if (d.perm && d.permcopy) { + errno = EINVAL; + return -1; + } if (!genalloc_append(chmod_directive, directives, &d)) - return 2; + return -1; /* errno = ENOMEM */ } } return 0; |