strcmp(1): further error-proofing

This commit is contained in:
dtb 2024-08-10 22:30:08 -06:00
parent 98c4d94f6d
commit 4c81516742
Signed by: trinity
GPG Key ID: 34C0543BBB6AF81B

View File

@ -26,18 +26,22 @@
char *program_name = "strcmp"; char *program_name = "strcmp";
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
program_name = argv[0] == NULL ? program_name : argv[0]; unsigned int i;
int i;
#ifdef __OpenBSD__ #ifdef __OpenBSD__
if (pledge("stdio", NULL) == -1) { if (pledge("stdio", NULL) == -1) {
perror(program_name); perror(argv[0] == NULL ? program_name : argv[0]);
return EX_OSERR; return EX_OSERR;
} }
#endif #endif
if (argc < 3) { if (argc < 3) {
(void)fprintf(stderr, "Usage: %s string string...\n", program_name); (void)fprintf(
stderr,
"Usage: %s string string...\n",
argv[0] == NULL ? program_name : argv[0]
);
return EX_USAGE; return EX_USAGE;
} }