commit: aff9f6426b53d394a46080742cc42c23b4e682d6
parent 98a9fead66ec397fbcb00378577d50a941ba5791
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 22 Mar 2025 04:35:06 +0100
Revert "cmd/*: gracefully handle errorneous long options"
This reverts commit 6cd739a74b65f2cca5e87130168cf6f5bdc46324.
Diffstat:
51 files changed, 51 insertions(+), 282 deletions(-)
diff --git a/cmd/base64.c b/cmd/base64.c
@@ -259,7 +259,7 @@ main(int argc, char *argv[])
int ret = 0;
- for(int c = -1; (c = getopt(argc, argv, ":dw:-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":dw:")) != -1;)
{
switch(c)
{
@@ -280,9 +280,6 @@ main(int argc, char *argv[])
return 1;
}
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/basename.c b/cmd/basename.c
@@ -49,7 +49,7 @@ main(int argc, char *argv[])
char *suffix = NULL;
char delim = '\n';
- for(int c = -1; (c = getopt(argc, argv, ":as:z-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":as:z")) != -1;)
{
switch(c)
{
@@ -63,10 +63,6 @@ main(int argc, char *argv[])
case 'z':
delim = '\0';
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/cat.c b/cmd/cat.c
@@ -24,17 +24,13 @@ usage(void)
int
main(int argc, char *argv[])
{
- for(int c = -1; (c = getopt(argc, argv, ":u-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":u")) != -1;)
{
switch(c)
{
case 'u':
// POSIX: Ignored, buffered streams aren't used
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/chmod.c b/cmd/chmod.c
@@ -356,7 +356,7 @@ main(int argc, char *argv[])
// Need + as first character to get POSIX-style option parsing
c = getopt_long(argc, argv, "+:cRv", opts, NULL);
#else
- c = getopt(argc, argv, ":cRv-:");
+ c = getopt(argc, argv, ":cRv");
#endif
if(c == -1) break;
@@ -374,12 +374,6 @@ main(int argc, char *argv[])
case 'v': // GNU
opt_v = true;
break;
-#ifdef HAS_GETOPT_LONG
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
-#endif
case ':':
if(optopt == '-') break;
diff --git a/cmd/chown.c b/cmd/chown.c
@@ -220,7 +220,7 @@ main(int argc, char *argv[])
// Need + as first character to get POSIX-style option parsing
for(int c = -1; (c = getopt_long(argc, argv, "+:hRHLPv", opts, NULL)) != -1;)
#else
- for(int c = -1; (c = getopt(argc, argv, ":hRHLPv-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":hRHLPv")) != -1;)
#endif
{
switch(c)
@@ -243,12 +243,6 @@ main(int argc, char *argv[])
case 'v':
opt_v = true;
break;
-#ifdef HAS_GETOPT_LONG
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
-#endif
case ':':
if(optopt == '-') break;
diff --git a/cmd/cmp.c b/cmd/cmp.c
@@ -97,7 +97,7 @@ main(int argc, char *argv[])
{
char *endptr = NULL;
- for(int c = -1; (c = getopt(argc, argv, ":ln:s-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":ln:s")) != -1;)
{
switch(c)
{
@@ -125,10 +125,6 @@ main(int argc, char *argv[])
return 1;
}
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/cut.c b/cmd/cut.c
@@ -376,7 +376,7 @@ main(int argc, char *argv[])
}
errno = 0;
- for(int c = -1; (c = getopt(argc, argv, ":b:c:d:f:ns-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":b:c:d:f:ns")) != -1;)
{
switch(c)
{
@@ -424,9 +424,6 @@ main(int argc, char *argv[])
case 's':
opt_s = true;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- return 1;
case ':':
fprintf(stderr, "%s: error: Option '-%c' requires an operand\n", argv0, optopt);
return 1;
diff --git a/cmd/date.c b/cmd/date.c
@@ -151,7 +151,7 @@ main(int argc, char *argv[])
return 1;
}
- for(int c = -1; (c = getopt(argc, argv, ":d:f:I:jr:Ru-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":d:f:I:jr:Ru")) != -1;)
{
const char *errstr = NULL;
switch(c)
@@ -261,10 +261,6 @@ main(int argc, char *argv[])
case 'j':
jflag = true;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/df.c b/cmd/df.c
@@ -50,7 +50,7 @@ main(int argc, char *argv[])
size_t only_count = 0;
char *only[4096];
- for(int c = -1; (c = getopt(argc, argv, ":ahilPkTt:x:-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":ahilPkTt:x:")) != -1;)
{
switch(c)
{
@@ -84,9 +84,6 @@ main(int argc, char *argv[])
case 'x':
excluded[excluded_count++] = optarg;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/env.c b/cmd/env.c
@@ -23,7 +23,6 @@
extern char **environ;
char *envclear[1];
-const char *argv0 = "env";
static int
do_export(void)
@@ -116,12 +115,6 @@ main(int argc, char *argv[])
}
break;
#endif
-#ifdef HAS_GETOPT_LONG
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
-#endif
case ':':
if(optopt == '-') break;
diff --git a/cmd/getconf.c b/cmd/getconf.c
@@ -17,8 +17,6 @@
// need to be after system headers
#include "./getconf_vars.h"
-const char *argv0 = "getconf";
-
static int
print_system_var(const char *var)
{
@@ -135,7 +133,7 @@ main(int argc, char *argv[])
bool o_all = false;
int c = -1;
- while((c = getopt(argc, argv, ":av:-:")) != -1)
+ while((c = getopt(argc, argv, ":av:")) != -1)
{
switch(c)
{
@@ -145,12 +143,6 @@ main(int argc, char *argv[])
case 'v':
fputs("getconf: -v option is unsupported\n", stderr);
return 1;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- return 1;
- case '?':
- fprintf(stderr, "%s: error: Unrecognised option '-%c'\n", argv0, optopt);
- return 1;
}
}
diff --git a/cmd/head.c b/cmd/head.c
@@ -168,7 +168,7 @@ main(int argc, char *argv[])
continue;
}
- int c = getopt(argc, argv, ":qvc:n:z-:");
+ int c = getopt(argc, argv, ":qvc:n:z");
if(c == -1) break;
switch(c)
@@ -218,10 +218,6 @@ main(int argc, char *argv[])
case 'z':
delim = '\0';
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/id.c b/cmd/id.c
@@ -188,7 +188,7 @@ main(int argc, char *argv[])
struct passwd pw = {.pw_uid = uid, .pw_gid = gid};
struct passwd epw = {.pw_uid = euid, .pw_gid = egid};
- for(int c = -1; (c = getopt(argc, argv, ":Ggunr-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":Ggunr")) != -1;)
{
switch(c)
{
@@ -207,10 +207,6 @@ main(int argc, char *argv[])
case 'r':
real_flag = true;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case '?':
fprintf(stderr, "%s: error: Unhandled option '-%c'\n", argv0, optopt);
usage();
diff --git a/cmd/install.c b/cmd/install.c
@@ -227,7 +227,7 @@ main(int argc, char *argv[])
// Need + as first character to get POSIX-style option parsing
for(int c = -1; (c = getopt_long(argc, argv, "+:CcDdpTt:g:m:o:v", opts, NULL)) != -1;)
#else
- for(int c = -1; (c = getopt(argc, argv, ":CcDdpTt:g:m:o:v-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":CcDdpTt:g:m:o:v")) != -1;)
#endif
{
switch(c)
@@ -271,12 +271,6 @@ main(int argc, char *argv[])
opt_v = true;
mkdir_parents_verbose = true;
break;
-#ifdef HAS_GETOPT_LONG
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
-#endif
case ':':
if(optopt == '-') break;
diff --git a/cmd/join.c b/cmd/join.c
@@ -127,7 +127,7 @@ main(int argc, char *argv[])
F2 = &input2;
aflag = vflag = 0;
- while((ch = getopt(argc, argv, ":a:e:j:1:2:o:t:v:-:")) != -1)
+ while((ch = getopt(argc, argv, ":a:e:j:1:2:o:t:v:")) != -1)
{
switch(ch)
{
@@ -195,10 +195,6 @@ main(int argc, char *argv[])
}
if(*end) utils_errx(1, "illegal file number -- %s", optarg);
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/ln.c b/cmd/ln.c
@@ -24,7 +24,6 @@
static bool opt_s = false, force = false;
static int link_flags = 0;
static int open_dir_flags = O_RDONLY | O_DIRECTORY;
-const char *argv0 = "ln";
static int
do_link(char *src, char *dest)
@@ -137,7 +136,7 @@ main(int argc, char *argv[])
{
bool verbose = false;
- for(int c = -1; (c = getopt(argc, argv, ":fnsLPv-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":fnsLPv")) != -1;)
{
switch(c)
{
@@ -159,10 +158,6 @@ main(int argc, char *argv[])
case 'v':
verbose = true;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case '?':
fprintf(stderr, "ln: error: Unknown option '-%c'\n", optopt);
usage();
diff --git a/cmd/mkdir.c b/cmd/mkdir.c
@@ -53,7 +53,7 @@ main(int argc, char *argv[])
const char *errstr = NULL;
// clang-format on
- for(int c = -1; (c = getopt(argc, argv, ":pvm:-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":pvm:")) != -1;)
{
switch(c)
{
@@ -71,10 +71,6 @@ main(int argc, char *argv[])
return 1;
}
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/mkfifo.c b/cmd/mkfifo.c
@@ -14,7 +14,6 @@
#include <unistd.h> // getopt
mode_t filemask;
-const char *argv0 = "mkfifo";
static void
usage(void)
@@ -29,7 +28,7 @@ main(int argc, char *argv[])
const char *errstr = NULL;
- for(int c = -1; (c = getopt(argc, argv, ":m:-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":m:")) != -1;)
{
switch(c)
{
@@ -41,10 +40,6 @@ main(int argc, char *argv[])
return 1;
}
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/mknod.c b/cmd/mknod.c
@@ -16,7 +16,6 @@
#include <unistd.h> // getopt
mode_t filemask;
-const char *argv0 = "mknod";
static void
usage(void)
@@ -53,7 +52,7 @@ main(int argc, char *argv[])
const char *errstr = NULL;
- for(int c = -1; (c = getopt(argc, argv, ":m:-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":m:")) != -1;)
{
switch(c)
{
@@ -65,10 +64,6 @@ main(int argc, char *argv[])
return 1;
}
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/mktemp.c b/cmd/mktemp.c
@@ -96,7 +96,7 @@ main(int argc, char *argv[])
// Need + as first character to get POSIX-style option parsing
for(int c = -1; (c = getopt_long(argc, argv, "+:dqp:tu", opts, NULL)) != -1;)
#else
- for(int c = -1; (c = getopt(argc, argv, ":dqp:tu-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":dqp:tu")) != -1;)
#endif
{
switch(c)
@@ -117,11 +117,6 @@ main(int argc, char *argv[])
case 'u':
o_unsafe = true;
break;
-#ifdef HAS_GETOPT_LONG
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- return 1;
-#endif
case '?':
fprintf(stderr, "%s: error: Unrecognised option: '-%c'\n", argv0, optopt);
return 1;
diff --git a/cmd/mv.c b/cmd/mv.c
@@ -392,7 +392,7 @@ main(int argc, char *argv[])
.sep = "",
};
- for(int c = -1; (c = getopt(argc, argv, ":fint:v-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":fint:v")) != -1;)
{
switch(c)
{
@@ -428,10 +428,6 @@ main(int argc, char *argv[])
case 'v':
verbose = true;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/nice.c b/cmd/nice.c
@@ -25,7 +25,7 @@ main(int argc, char *argv[])
{
long incr = 0;
- for(int c = -1; (c = getopt(argc, argv, ":n:-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":n:")) != -1;)
{
char *endptr = NULL;
@@ -46,10 +46,6 @@ main(int argc, char *argv[])
return 125;
}
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/nproc.c b/cmd/nproc.c
@@ -29,7 +29,7 @@ main(int argc, char *argv[])
int target = _SC_NPROCESSORS_ONLN;
const char *target_str = "_SC_NPROCESSORS_ONLN";
- for(int c = -1; (c = getopt(argc, argv, ":a-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":a")) != -1;)
{
switch(c)
{
@@ -37,10 +37,6 @@ main(int argc, char *argv[])
target = _SC_NPROCESSORS_CONF;
target_str = "_SC_NPROCESSORS_CONF";
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/paste.c b/cmd/paste.c
@@ -223,7 +223,7 @@ main(int argc, char *argv[])
int seq = 0;
- for(int c = -1; (c = getopt(argc, argv, ":d:sz-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":d:sz")) != -1;)
{
switch(c)
{
@@ -247,10 +247,6 @@ main(int argc, char *argv[])
case 'z':
linedelim = L'\0';
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/pathchk.c b/cmd/pathchk.c
@@ -12,8 +12,6 @@
#include <sys/stat.h> // lstat
#include <unistd.h> // getopt
-const char *argv0 = "pathchk";
-
// POSIX Portable Character Set
// Returns 0 on success, or the first invalid character found
static char
@@ -44,7 +42,7 @@ main(int argc, char *argv[])
size_t path_max = PATH_MAX - 1;
size_t name_max = NAME_MAX;
- for(int c = -1; (c = getopt(argc, argv, ":pP-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":pP")) != -1;)
{
switch(c)
{
@@ -56,10 +54,6 @@ main(int argc, char *argv[])
path_max = _POSIX_PATH_MAX - 1;
name_max = _POSIX_NAME_MAX;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/printf.c b/cmd/printf.c
@@ -105,14 +105,10 @@ main(int argc, char *argv[])
strerror(errno));
}
- for(int c = -1; (c = getopt(argc, argv, ":-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, "")) != -1;)
{
switch(c)
{
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case '?':
default:
usage();
diff --git a/cmd/pwd.c b/cmd/pwd.c
@@ -74,7 +74,7 @@ main(int argc, char *argv[])
{
enum pwd mode = PWD_L;
- for(int c = -1; (c = getopt(argc, argv, ":LP-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":LP")) != -1;)
{
switch(c)
{
@@ -84,10 +84,6 @@ main(int argc, char *argv[])
case 'P':
mode = PWD_P;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/realpath.c b/cmd/realpath.c
@@ -97,7 +97,7 @@ main_realpath(int argc, char *argv[])
int offset_sep = 0;
- for(int c = -1; (c = getopt(argc, argv, ":Eemnsz-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":Eemnsz")) != -1;)
{
switch(c)
{
@@ -116,10 +116,6 @@ main_realpath(int argc, char *argv[])
case 'z':
sep = '\0';
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage_realpath();
- return 1;
case ':':
if(optopt == '-') break;
@@ -167,7 +163,7 @@ main_readlink(int argc, char *argv[])
int offset_sep = 0;
- for(int c = -1; (c = getopt(argc, argv, ":femnz-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":femnz")) != -1;)
{
switch(c)
{
@@ -184,10 +180,6 @@ main_readlink(int argc, char *argv[])
case 'z':
sep = '\0';
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage_readlink();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/renice.c b/cmd/renice.c
@@ -12,8 +12,6 @@
#include <sys/resource.h> // getpriority, setpriority
#include <unistd.h> // getopt, nice
-const char *argv0 = "renice";
-
static int
renice(int which, id_t who, int adj)
{
@@ -73,7 +71,7 @@ main(int argc, char *argv[])
long adj = 0;
int which = PRIO_PROCESS;
- for(int c = -1; (c = getopt(argc, argv, ":gpun:-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":gpun:")) != -1;)
{
char *endptr = NULL;
@@ -117,10 +115,6 @@ main(int argc, char *argv[])
return 1;
}
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/rm.c b/cmd/rm.c
@@ -169,7 +169,7 @@ usage(void)
int
main(int argc, char *argv[])
{
- for(int c = -1; (c = getopt(argc, argv, ":dfirRv-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":dfirRv")) != -1;)
{
switch(c)
{
@@ -191,10 +191,6 @@ main(int argc, char *argv[])
case 'v':
verbose = true;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/rmdir.c b/cmd/rmdir.c
@@ -15,8 +15,6 @@
#include <getopt.h>
#endif
-const char *argv0 = "rmdir";
-
static void
usage(void)
{
@@ -48,7 +46,7 @@ main(int argc, char *argv[])
// Need + as first character to get POSIX-style option parsing
for(int c = -1; (c = getopt_long(argc, argv, "+:pv", opts, NULL)) != -1;)
#else
- for(int c = -1; (c = getopt(argc, argv, ":pv-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":pv")) != -1;)
#endif
{
switch(c)
@@ -64,12 +62,6 @@ main(int argc, char *argv[])
case 'v':
verbose = true;
break;
-#ifdef HAS_GETOPT_LONG
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
-#endif
case ':':
if(optopt == '-') break;
diff --git a/cmd/seq.c b/cmd/seq.c
@@ -12,8 +12,6 @@
#include <string.h> // strerror
#include <unistd.h> // getopt, optarg, optind
-const char *argv0 = "seq";
-
const char *sep = "\n";
const char *term = "\n";
@@ -80,7 +78,7 @@ usage(void)
int
main(int argc, char *argv[])
{
- for(int c = -1; (c = getopt(argc, argv, ":ws:t:-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":ws:t:")) != -1;)
{
switch(c)
{
@@ -93,10 +91,6 @@ main(int argc, char *argv[])
case 't':
term = optarg;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
fprintf(stderr, "seq: error: Option -%c requires an operand\n", optopt);
usage();
diff --git a/cmd/sha1sum.c b/cmd/sha1sum.c
@@ -167,16 +167,13 @@ main(int argc, char *argv[])
{
bool opt_c = false;
- for(int c = -1; (c = getopt(argc, argv, ":c-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":c")) != -1;)
{
switch(c)
{
case 'c':
opt_c = true;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/sha256sum.c b/cmd/sha256sum.c
@@ -167,16 +167,13 @@ main(int argc, char *argv[])
{
bool opt_c = false;
- for(int c = -1; (c = getopt(argc, argv, ":c-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":c")) != -1;)
{
switch(c)
{
case 'c':
opt_c = true;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/sha512sum.c b/cmd/sha512sum.c
@@ -167,16 +167,13 @@ main(int argc, char *argv[])
{
bool opt_c = false;
- for(int c = -1; (c = getopt(argc, argv, ":c-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":c")) != -1;)
{
switch(c)
{
case 'c':
opt_c = true;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/shuf.c b/cmd/shuf.c
@@ -92,7 +92,7 @@ main(int argc, char *argv[])
bool e_flag = false;
srand((int)time(NULL));
- for(int c = -1; (c = getopt(argc, argv, ":en:z-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":en:z")) != -1;)
{
char *endptr = NULL;
@@ -126,10 +126,6 @@ main(int argc, char *argv[])
case 'z':
delim = '\0';
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/split.c b/cmd/split.c
@@ -233,7 +233,7 @@ static const char *error_opt_b_l = "%s: error: Options -b and -l are mutually ex
int
main(int argc, char *argv[])
{
- for(int c = -1; (c = getopt(argc, argv, ":a:b:l:-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":a:b:l:")) != -1;)
{
char *endptr = NULL;
@@ -301,9 +301,6 @@ main(int argc, char *argv[])
return 1;
}
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- return 1;
case ':':
fprintf(stderr, "%s: error: Option '-%c' requires an operand\n", argv0, optopt);
return 1;
diff --git a/cmd/strings.c b/cmd/strings.c
@@ -12,8 +12,6 @@
#include <string.h> /* strerror(), strncmp() */
#include <unistd.h> /* read(), write(), close(), getopt(), optarg, optind */
-const char *argv0 = "strings";
-
size_t opt_min_strlen = 4;
const char *opt_offset_format = NULL;
int delim = '\n';
@@ -104,7 +102,7 @@ usage(void)
int
main(int argc, char *argv[])
{
- for(int c = -1; (c = getopt(argc, argv, ":an:t:z-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":an:t:z")) != -1;)
{
char *endptr = NULL;
@@ -166,10 +164,6 @@ main(int argc, char *argv[])
case 'z':
delim = '\0';
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/sync.c b/cmd/sync.c
@@ -16,15 +16,13 @@
#include <string.h> // strerror
#include <unistd.h> // fsync, sync, getopt, syncfs
-const char *argv0 = "sync";
-
int
main(int argc, char *argv[])
{
int err = 0;
int (*sync_func)(int) = fsync;
- for(int c = -1; (c = getopt(argc, argv, ":df-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":df")) != -1;)
{
switch(c)
{
@@ -41,9 +39,6 @@ main(int argc, char *argv[])
err = 1;
break;
#endif
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- return 1;
case '?':
fprintf(stderr,
"sync: error: Unrecognized option '-%c', continuing with error status set\n",
diff --git a/cmd/tee.c b/cmd/tee.c
@@ -11,8 +11,6 @@
#include <string.h> /* strerror() */
#include <unistd.h> /* getopt(), opt… */
-const char *argv0 = "tee";
-
static void
cleanup(FILE **fds)
{
@@ -29,7 +27,7 @@ main(int argc, char *argv[])
FILE **fds = {NULL}; // Shut up GCC
int c;
- for(int c = -1; (c = getopt(argc, argv, ":ai-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":ai")) != -1;)
{
switch(c)
{
@@ -39,9 +37,6 @@ main(int argc, char *argv[])
case 'i': /* ignore SIGINT */;
signal(SIGINT, SIG_IGN);
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/time.c b/cmd/time.c
@@ -12,8 +12,6 @@
#include <sys/wait.h> // waitpid
#include <unistd.h> // sysconf, fork, execvp, getopt
-const char *argv0 = "time";
-
enum cmd_time_mode
{
CMD_TIME_POSIX = 0,
@@ -39,7 +37,7 @@ main(int argc, char *argv[])
return 0;
}
- for(int c = -1; (c = getopt(argc, argv, ":pv-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":pv")) != -1;)
{
switch(c)
{
@@ -49,10 +47,6 @@ main(int argc, char *argv[])
case 'v':
mode = CMD_TIME_VERBOSE;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/timeout.c b/cmd/timeout.c
@@ -60,7 +60,7 @@ main(int argc, char *argv[])
char *arg = NULL;
- for(int c = -1; (c = getopt(argc, argv, ":fk:ps:-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":fk:ps:")) != -1;)
{
switch(c)
{
@@ -136,10 +136,6 @@ main(int argc, char *argv[])
}
}
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/touch.c b/cmd/touch.c
@@ -19,8 +19,6 @@
#include <time.h> /* mktime */
#include <unistd.h> /* getopt, opt*, close */
-const char *argv0 = "touch";
-
// [[CC]YY]MMDDhhmm[.SS]
static struct timespec
opt_t_parse(char *arg, const char **errstr)
@@ -125,7 +123,7 @@ main(int argc, char *argv[])
int open_flags = O_WRONLY | O_CREAT | O_NOCTTY;
int utimensat_flags = 0;
- for(int c = -1; (c = getopt(argc, argv, ":acfhmr:t:d:-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":acfhmr:t:d:")) != -1;)
{
const char *errstr = NULL;
@@ -204,9 +202,6 @@ main(int argc, char *argv[])
errno = 0;
break;
}
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/tr.c b/cmd/tr.c
@@ -77,7 +77,7 @@ main(int argc, char *argv[])
int cflag, dflag, sflag;
cflag = dflag = sflag = 0;
- for(int c = -1; (c = getopt(argc, argv, "Ccds-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, "Ccds")) != -1;)
{
switch(c)
{
@@ -91,10 +91,6 @@ main(int argc, char *argv[])
case 's':
sflag = 1;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
fprintf(stderr, "%s: error: Option '-%c' requires an operand\n", argv0, optopt);
usage();
diff --git a/cmd/truncate.c b/cmd/truncate.c
@@ -36,7 +36,7 @@ main(int argc, char *argv[])
};
char *ref_file = NULL;
- for(int c = -1; (c = getopt(argc, argv, ":cr:s:-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":cr:s:")) != -1;)
{
switch(c)
{
@@ -67,10 +67,6 @@ main(int argc, char *argv[])
}
size_set = true;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/uname.c b/cmd/uname.c
@@ -12,8 +12,6 @@
#include <sys/utsname.h> // uname
#include <unistd.h> // getopt
-const char *argv0 = "uname";
-
enum uname_names
{
CMD_UNAME_SYSNAME = 1 << 1,
@@ -51,7 +49,7 @@ usage(void)
int
main(int argc, char *argv[])
{
- for(int c = -1; (c = getopt(argc, argv, ":amnprsv-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":amnprsv")) != -1;)
{
switch(c)
{
@@ -74,10 +72,6 @@ main(int argc, char *argv[])
case 'v':
names |= CMD_UNAME_VERSION;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
case ':':
if(optopt == '-') break;
diff --git a/cmd/uniq.c b/cmd/uniq.c
@@ -30,7 +30,7 @@ main(int argc, char *argv[])
char *endptr = NULL;
- for(int c = -1; (c = getopt(argc, argv, ":cdf:s:u-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":cdf:s:u")) != -1;)
{
switch(c)
{
@@ -94,9 +94,6 @@ main(int argc, char *argv[])
}
mode = NO_REPEAT;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- return 1;
case ':':
fprintf(stderr, "%s: error: Option '-%c' requires an operand\n", argv0, optopt);
return 1;
diff --git a/cmd/wc.c b/cmd/wc.c
@@ -237,7 +237,7 @@ main(int argc, char *argv[])
// Need + as first character to get POSIX-style option parsing
for(int c = -1; (c = getopt_long(argc, argv, "+:clmw", opts, NULL)) != -1;)
#else
- for(int c = -1; (c = getopt(argc, argv, ":clmw-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, ":clmw")) != -1;)
#endif
{
switch(c)
@@ -256,12 +256,6 @@ main(int argc, char *argv[])
case 'w':
wc_opts |= WC_OPT_W;
break;
-#ifdef HAS_GETOPT_LONG
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- usage();
- return 1;
-#endif
case ':':
if(optopt == '-') break;
diff --git a/cmd/which.c b/cmd/which.c
@@ -11,8 +11,6 @@
#include <string.h> // strtok
#include <unistd.h> // access, getopt
-const char *argv0 = "which";
-
int
main(int argc, char *argv[])
{
@@ -26,7 +24,7 @@ main(int argc, char *argv[])
return 1;
}
- for(int c = -1; (c = getopt(argc, argv, "as-:")) != -1;)
+ for(int c = -1; (c = getopt(argc, argv, "as")) != -1;)
{
switch(c)
{
@@ -36,9 +34,6 @@ main(int argc, char *argv[])
case 's':
opt_s = true;
break;
- case '-':
- fprintf(stderr, "%s: error: Unsupported long option: '--%s'\n", argv0, optarg);
- return 1;
case '?':
fprintf(stderr, "which: error: Unrecognised option: '-%c'\n", optopt);
return 1;
diff --git a/test-cmd/cat.sh b/test-cmd/cat.sh
@@ -47,6 +47,6 @@ t --exit=1 enoent /var/empty/e/no/ent "cat: error: Failed opening file '/var/emp
t_file doubledash "$WD/inputs/all_bytes" -- "$WD/inputs/all_bytes"
-t --exit=1 tripledash "--- $WD/inputs/all_bytes" "cat: error: Unsupported long option: '---'
+t --exit=1 tripledash "--- $WD/inputs/all_bytes" "cat: error: Unrecognised option: '--'
Usage: cat [-u] [files ...]
"
diff --git a/test-cmd/tee.sh b/test-cmd/tee.sh
@@ -45,5 +45,5 @@ t --exit=1 --input='foo' enoent '/var/empty/e/no/ent' 'tee: error: Failed openin
t_file --infile="${WD}/inputs/all_bytes" doubledash "${WD}/inputs/all_bytes" --
-t --exit=1 --input='foo' tripledash '---' "tee: error: Unsupported long option: '---'
+t --exit=1 --input='foo' tripledash '---' "tee: error: Unrecognised option: '--'
"