Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c810fd1

Browse files
committedMar 3, 2024
bin/*: correct error message for invalid long option specification
The commands under "bin/" output the error messages by themselves by setting opterr to 0, and are compatible with getopt_long, but if an invalid long option is specified, the option that causes the error will not be displayed as shown below: lscp: invalid option -- Also lscp and lssu do not properly display error messages for options that require an additional argument and it is not provided. Fix these issues by not setting opterr to 0 and leaving error output for argument options to getopt() or getopt_long()'s built-in features. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
1 parent bfb6c54 commit c810fd1

File tree

6 files changed

+6
-14
lines changed

6 files changed

+6
-14
lines changed
 

‎bin/chcp.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ int main(int argc, char *argv[])
8686
#endif /* _GNU_SOURCE */
8787
sigset_t sigset, oldset;
8888

89-
opterr = 0;
90-
9189
last = strrchr(argv[0], '/');
9290
progname = last ? last + 1 : argv[0];
9391

@@ -107,7 +105,7 @@ int main(int argc, char *argv[])
107105
PACKAGE_VERSION);
108106
exit(EXIT_SUCCESS);
109107
default:
110-
errx(EXIT_FAILURE, "invalid option -- %c", optopt);
108+
exit(EXIT_FAILURE);
111109
}
112110
}
113111

‎bin/dumpseg.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ int main(int argc, char *argv[])
183183
int option_index;
184184
#endif /* _GNU_SOURCE */
185185

186-
opterr = 0;
187-
188186
last = strrchr(argv[0], '/');
189187
progname = last ? last + 1 : argv[0];
190188

@@ -204,7 +202,7 @@ int main(int argc, char *argv[])
204202
PACKAGE_VERSION);
205203
exit(EXIT_SUCCESS);
206204
default:
207-
errx(EXIT_FAILURE, "invalid option -- %c", optopt);
205+
exit(EXIT_FAILURE);
208206
}
209207
}
210208

‎bin/lscp.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,6 @@ int main(int argc, char *argv[])
417417

418418
mode = NILFS_CHECKPOINT;
419419
rvs = 0;
420-
opterr = 0; /* prevent error message */
421420
progname = strrchr(argv[0], '/');
422421
if (progname == NULL)
423422
progname = argv[0];
@@ -462,7 +461,7 @@ int main(int argc, char *argv[])
462461
PACKAGE_VERSION);
463462
exit(EXIT_SUCCESS);
464463
default:
465-
errx(EXIT_FAILURE, "invalid option -- %c", optopt);
464+
exit(EXIT_FAILURE);
466465
}
467466
}
468467

‎bin/lssu.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ int main(int argc, char *argv[])
298298
int option_index;
299299
#endif /* _GNU_SOURCE */
300300

301-
opterr = 0;
302301
progname = strrchr(argv[0], '/');
303302
if (progname == NULL)
304303
progname = argv[0];
@@ -345,7 +344,7 @@ int main(int argc, char *argv[])
345344
PACKAGE_VERSION);
346345
exit(EXIT_SUCCESS);
347346
default:
348-
errx(EXIT_FAILURE, "invalid option -- %c", optopt);
347+
exit(EXIT_FAILURE);
349348
}
350349
}
351350

‎bin/mkcp.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ int main(int argc, char *argv[])
8181

8282
ss = 0;
8383
print = 0;
84-
opterr = 0;
8584
last = strrchr(argv[0], '/');
8685
progname = last ? last + 1 : argv[0];
8786

@@ -107,7 +106,7 @@ int main(int argc, char *argv[])
107106
PACKAGE_VERSION);
108107
exit(EXIT_SUCCESS);
109108
default:
110-
errx(EXIT_FAILURE, "invalid option -- %c", optopt);
109+
exit(EXIT_FAILURE);
111110
}
112111
}
113112

‎bin/rmcp.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ int main(int argc, char *argv[])
147147
int option_index;
148148
#endif /* _GNU_SOURCE */
149149

150-
opterr = 0;
151150
last = strrchr(argv[0], '/');
152151
progname = last ? last + 1 : argv[0];
153152

@@ -175,7 +174,7 @@ int main(int argc, char *argv[])
175174
PACKAGE_VERSION);
176175
exit(EXIT_SUCCESS);
177176
default:
178-
errx(EXIT_FAILURE, "invalid option -- %c", optopt);
177+
exit(EXIT_FAILURE);
179178
}
180179
}
181180

0 commit comments

Comments
 (0)
Please sign in to comment.