diff options
author | Frederic Cambus <fcambus@cvs.openbsd.org> | 2016-09-16 09:25:24 +0000 |
---|---|---|
committer | Frederic Cambus <fcambus@cvs.openbsd.org> | 2016-09-16 09:25:24 +0000 |
commit | 48edb702b2da924ff8a9cdac835b28baf2b04f56 (patch) | |
tree | a13eb32c7fbc2e006e28838c120bb97bc542ff93 /usr.bin | |
parent | 5979c88a48a359cb1615726d4a1c3dc8508530e7 (diff) |
- Removed unnecessary string.h include
- Changed 'format_and_print' argument type to int64_t and casting
inside the function
- Declaring 'print_counts', 'format_and_print', and 'cnt' as static
- Remove unnecessary cast for NULL, and (void) casts from printfs,
'mbtowc' and 'format_and_print' calls
- In 'cnt', change bufsz type from ssize_t to size_t to avoid
converting between pointers to integer types with different sign
when calling getline (catched when compiling with Clang)
- Use return instead of exit in main
OK jung@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/wc/wc.c | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/usr.bin/wc/wc.c b/usr.bin/wc/wc.c index 5813f44a73d..e92a9fca2b1 100644 --- a/usr.bin/wc/wc.c +++ b/usr.bin/wc/wc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wc.c,v 1.20 2015/12/08 01:00:45 schwarze Exp $ */ +/* $OpenBSD: wc.c,v 1.21 2016/09/16 09:25:23 fcambus Exp $ */ /* * Copyright (c) 1980, 1987, 1991, 1993 @@ -34,7 +34,6 @@ #include <sys/file.h> #include <stdio.h> #include <stdlib.h> -#include <string.h> #include <locale.h> #include <ctype.h> #include <err.h> @@ -45,12 +44,12 @@ int64_t tlinect, twordct, tcharct; int doline, doword, dochar, humanchar, multibyte; -int rval; +int rval; extern char *__progname; -void print_counts(int64_t, int64_t, int64_t, char *); -void format_and_print(long long); -void cnt(char *); +static void print_counts(int64_t, int64_t, int64_t, char *); +static void format_and_print(int64_t); +static void cnt(char *); int main(int argc, char *argv[]) @@ -82,10 +81,10 @@ main(int argc, char *argv[]) break; case '?': default: - (void)fprintf(stderr, + fprintf(stderr, "usage: %s [-c | -m] [-hlw] [file ...]\n", __progname); - exit(1); + return 1; } argv += optind; argc -= optind; @@ -99,7 +98,7 @@ main(int argc, char *argv[]) doline = doword = dochar = 1; if (!*argv) { - cnt((char *)NULL); + cnt(NULL); } else { int dototal = (argc > 1); @@ -111,14 +110,14 @@ main(int argc, char *argv[]) print_counts(tlinect, twordct, tcharct, "total"); } - exit(rval); + return rval; } -void +static void cnt(char *file) { static char *buf; - static ssize_t bufsz; + static size_t bufsz; FILE *stream; char *C; @@ -213,7 +212,7 @@ cnt(char *file) ++charct; len = mbtowc(&wc, C, MB_CUR_MAX); if (len == -1) { - (void)mbtowc(NULL, NULL, + mbtowc(NULL, NULL, MB_CUR_MAX); len = 1; wc = L' '; @@ -263,31 +262,31 @@ cnt(char *file) } } -void -format_and_print(long long v) +static void +format_and_print(int64_t v) { if (humanchar) { char result[FMT_SCALED_STRSIZE]; - (void)fmt_scaled(v, result); - (void)printf("%7s", result); + fmt_scaled((long long)v, result); + printf("%7s", result); } else { - (void)printf(" %7lld", v); + printf(" %7lld", v); } } -void +static void print_counts(int64_t lines, int64_t words, int64_t chars, char *name) { if (doline) - format_and_print((long long)lines); + format_and_print(lines); if (doword) - format_and_print((long long)words); + format_and_print(words); if (dochar) - format_and_print((long long)chars); + format_and_print(chars); if (name) - (void)printf(" %s\n", name); + printf(" %s\n", name); else - (void)printf("\n"); + printf("\n"); } |