diff options
author | cheloha <cheloha@openbsd.org> | 2020-12-04 02:25:56 +0000 |
---|---|---|
committer | cheloha <cheloha@openbsd.org> | 2020-12-04 02:25:56 +0000 |
commit | 2112a9335ac99e5fab9cf094ba46d5b0af68fa4c (patch) | |
tree | ef0f5a8d7186d025d823d6c239f7680780f350aa /bin | |
parent | make program name be const (diff) | |
download | wireguard-openbsd-2112a9335ac99e5fab9cf094ba46d5b0af68fa4c.tar.xz wireguard-openbsd-2112a9335ac99e5fab9cf094ba46d5b0af68fa4c.zip |
cat(1): misc. style(9)
- Use getprogname(3) instead of __progname.
- Sprinkle in some missing braces.
- Prefer err(..., NULL) when malloc(3) fails.
- Remove an unnecessary cast to from ssize_t to size_t.
Diffstat (limited to 'bin')
-rw-r--r-- | bin/cat/cat.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/bin/cat/cat.c b/bin/cat/cat.c index fa35136a250..1f2208bf74b 100644 --- a/bin/cat/cat.c +++ b/bin/cat/cat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cat.c,v 1.29 2020/12/04 01:42:05 cheloha Exp $ */ +/* $OpenBSD: cat.c,v 1.30 2020/12/04 02:25:56 cheloha Exp $ */ /* $NetBSD: cat.c,v 1.11 1995/09/07 06:12:54 jtc Exp $ */ /* @@ -47,8 +47,6 @@ #define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b)) -extern char *__progname; - int bflag, eflag, nflag, sflag, tflag, vflag; int rval; @@ -65,7 +63,7 @@ main(int argc, char *argv[]) if (pledge("stdio rpath", NULL) == -1) err(1, "pledge"); - while ((ch = getopt(argc, argv, "benstuv")) != -1) + while ((ch = getopt(argc, argv, "benstuv")) != -1) { switch (ch) { case 'b': bflag = nflag = 1; /* -b implies -n */ @@ -89,10 +87,11 @@ main(int argc, char *argv[]) vflag = 1; break; default: - (void)fprintf(stderr, - "usage: %s [-benstuv] [file ...]\n", __progname); + fprintf(stderr, "usage: %s [-benstuv] [file ...]\n", + getprogname()); return 1; } + } argv += optind; if (bflag || eflag || nflag || sflag || tflag || vflag) @@ -233,13 +232,14 @@ raw_cat(int rfd, const char *filename) err(1, "stdout"); bsize = MAXIMUM(sbuf.st_blksize, BUFSIZ); if ((buf = malloc(bsize)) == NULL) - err(1, "malloc"); + err(1, NULL); } - while ((nr = read(rfd, buf, bsize)) != -1 && nr != 0) - for (off = 0; nr; nr -= nw, off += nw) - if ((nw = write(wfd, buf + off, (size_t)nr)) == 0 || - nw == -1) + while ((nr = read(rfd, buf, bsize)) != -1 && nr != 0) { + for (off = 0; nr; nr -= nw, off += nw) { + if ((nw = write(wfd, buf + off, nr)) == -1 || nw == 0) err(1, "stdout"); + } + } if (nr == -1) { warn("%s", filename); rval = 1; |