diff options
author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2024-01-12 15:40:40 +0000 |
---|---|---|
committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2024-01-12 15:44:00 +0000 |
commit | e2ec8ee02a33e39b8ff86a56e8a1ef5e84ac7e62 (patch) | |
tree | 00d2ce75e271176bb074763f2b847cee3687a244 | |
parent | 11715600e626cf6cc4b4f564af97f6ae1e5fb0be (diff) | |
download | src-e2ec8ee02a33e39b8ff86a56e8a1ef5e84ac7e62.tar.gz src-e2ec8ee02a33e39b8ff86a56e8a1ef5e84ac7e62.zip |
uniq: Clean up and test obsolete options.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D43402
-rwxr-xr-x | usr.bin/uniq/tests/uniq_test.sh | 3 | ||||
-rw-r--r-- | usr.bin/uniq/uniq.c | 14 |
2 files changed, 8 insertions, 9 deletions
diff --git a/usr.bin/uniq/tests/uniq_test.sh b/usr.bin/uniq/tests/uniq_test.sh index 8dc2015734f6..537962eb6513 100755 --- a/usr.bin/uniq/tests/uniq_test.sh +++ b/usr.bin/uniq/tests/uniq_test.sh @@ -74,6 +74,7 @@ skip_fields_head() { skip_fields_body() { printf "1 a\n2 a\n3 b\n4 b\n5 a\n6 a\n" >input printf "1 a\n3 b\n5 a\n" >expected + atf_check_uniq -1 atf_check_uniq -f 1 atf_check_uniq --skip-fields 1 } @@ -85,6 +86,7 @@ skip_fields_tab_head() { skip_fields_tab_body() { printf "1\ta\n2\ta\n3\tb\n4\tb\n5\ta\n6\ta\n" >input printf "1\ta\n3\tb\n5\ta\n" >expected + atf_check_uniq -1 atf_check_uniq -f 1 atf_check_uniq --skip-fields 1 } @@ -107,6 +109,7 @@ skip_chars_head() { skip_chars_body() { printf "1 a\n2 a\n3 b\n4 b\n5 a\n6 a\n" >input printf "1 a\n3 b\n5 a\n" >expected + atf_check_uniq +2 atf_check_uniq -s 2 atf_check_uniq --skip-chars 2 } diff --git a/usr.bin/uniq/uniq.c b/usr.bin/uniq/uniq.c index 0bc9b2b86af3..ef59d7339d0c 100644 --- a/usr.bin/uniq/uniq.c +++ b/usr.bin/uniq/uniq.c @@ -338,29 +338,25 @@ file(const char *name, const char *mode) static void obsolete(char *argv[]) { - int len; - char *ap, *p, *start; + char *ap, *p; while ((ap = *++argv)) { /* Return if "--" or not an option of any form. */ if (ap[0] != '-') { if (ap[0] != '+') return; - } else if (ap[1] == '-') + } else if (ap[1] == '-') { return; + } if (!isdigit((unsigned char)ap[1])) continue; /* * Digit signifies an old-style option. Malloc space for dash, * new option and argument. */ - len = strlen(ap); - if ((start = p = malloc(len + 3)) == NULL) + if (asprintf(&p, "-%c%s", ap[0] == '+' ? 's' : 'f', ap + 1) < 0) err(1, "malloc"); - *p++ = '-'; - *p++ = ap[0] == '+' ? 's' : 'f'; - (void)strcpy(p, ap + 1); - *argv = start; + *argv = p; } } |