diff options
author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2023-09-06 03:28:25 +0000 |
---|---|---|
committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2023-09-06 03:29:31 +0000 |
commit | 851bf856d1a7ad5427ea9c22639ab6f6c4a3f503 (patch) | |
tree | 700142fb886f38c763d55adc14672cb15b1e9c85 | |
parent | cbea5eddb1b6ae2a101beacf00bf165517f4f2b1 (diff) | |
download | src-851bf856d1a7ad5427ea9c22639ab6f6c4a3f503.tar.gz src-851bf856d1a7ad5427ea9c22639ab6f6c4a3f503.zip |
split: Code cleanup.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D41756
-rw-r--r-- | usr.bin/split/split.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/usr.bin/split/split.c b/usr.bin/split/split.c index b5a457ab6ecd..6894e9e63195 100644 --- a/usr.bin/split/split.c +++ b/usr.bin/split/split.c @@ -41,7 +41,6 @@ static const char sccsid[] = "@(#)split.c 8.2 (Berkeley) 4/16/94"; #endif #include <sys/param.h> -#include <sys/types.h> #include <sys/stat.h> #include <ctype.h> @@ -85,9 +84,9 @@ static void usage(void) __dead2; int main(int argc, char **argv) { - int ch; - int error; - char *ep, *p; + const char *p; + char *ep; + int ch, error; setlocale(LC_ALL, ""); @@ -157,17 +156,22 @@ main(int argc, char **argv) argv += optind; argc -= optind; - if (*argv != NULL) { /* Input file. */ + if (argc > 0) { /* Input file. */ if (strcmp(*argv, "-") == 0) ifd = STDIN_FILENO; else if ((ifd = open(*argv, O_RDONLY, 0)) < 0) err(EX_NOINPUT, "%s", *argv); ++argv; + --argc; } - if (*argv != NULL) /* File name prefix. */ - if (strlcpy(fname, *argv++, sizeof(fname)) >= sizeof(fname)) - errx(EX_USAGE, "file name prefix is too long"); - if (*argv != NULL) + if (argc > 0) { /* File name prefix. */ + if (strlcpy(fname, *argv, sizeof(fname)) >= sizeof(fname)) + errx(EX_USAGE, "file name prefix is too long: %s", + *argv); + ++argv; + --argc; + } + if (argc > 0) usage(); if (strlen(fname) + (unsigned long)sufflen >= sizeof(fname)) @@ -400,7 +404,6 @@ newfile(void) sufflen++; /* Reset so we start back at all 'a's in our extended suffix. */ - tfnum = 0; fnum = 0; } |