Author | Jamozed <[email protected]> |
Date | 2020-07-06 10:11:16 |
Commit | 934dc2eef027c45b00bd594499f851f5607232e0 |
Parent | f9068a8b71e64d2fe6019c9f7318a4f5322d8c2b |
cat: Use libokv error reporting
Diffstat
M | src/cat.c | | | 19 | +++++++++---------- |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/cat.c b/src/cat.c index 12164d7..46a4c8c 100644 --- a/src/cat.c +++ b/src/cat.c @@ -1,4 +1,4 @@ -// cat.c, version 1.0.3 +// cat.c, version 1.0.4 // OMKOV coreutils implementation of POSIX cat // Copyright (C) 2020, Jakob Wakeling // All rights reserved. @@ -33,22 +33,21 @@ 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 <errno.h> +#include <error.h> + #include <stdbool.h> #include <stdio.h> -#include <string.h> -#define VERSION "1.0.3" +#define VERSION "1.0.4" static inline int cat(const char *file); 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 }, @@ -56,7 +55,7 @@ int main(int argc, char *argv[]) { }; opt_t opt = OPTGET_INIT; opt.str = "u"; opt.lops = lops; int o; - while ((o = optget(&opt, argv, 1)) != -1) switch (o) { + while ((o = optget(&opt, av, 1)) != -1) switch (o) { case 'u': { break; } case 256: { help(); return 0; } case 257: { version(); return 0; } @@ -66,9 +65,9 @@ int main(int argc, char *argv[]) { setvbuf(stdout, NULL, _IONBF, 0); bool warned = false; - if (opt.ind == argc) { cat("-"); } - else for (char **p = &argv[opt.ind]; *p; ++p) if (cat(*p)) { - warn("%s: %s: %s", argv[0], *p, serrno); warned = true; + if (opt.ind == ac) { cat("-"); } + else for (char **p = &av[opt.ind]; *p; ++p) if (cat(*p)) { + warn("%s: %s", *p, serr()); warned = true; } return warned;