dj(1): use entirely-stdio error messages for OpenBSD functions

This commit is contained in:
dtb 2024-08-10 22:03:59 -06:00
parent a693ced9d9
commit b1a4a1a2b9
Signed by: trinity
GPG Key ID: 34C0543BBB6AF81B

View File

@ -108,8 +108,10 @@ Io_write(struct Io *io) {
}
static int
oserr(char *e, int n) {
(void)fprintf(stderr, "%s: %s: %s\n", program_name, e, strerror(n));
oserr(char *e, int n) { /* program_name: [failing component:] error */
(void)fprintf(stderr, "%s: ", program_name);
if (e != NULL) { (void)fprintf(stderr, "%s: ", e); }
(void)fprintf(stderr, "%s\n", strerror(n));
return EX_OSERR;
}
@ -170,7 +172,7 @@ usage(char *argv0) {
int main(int argc, char *argv[]) {
#ifdef __OpenBSD__
if (pledge("cpath rpath stdio unveil wpath", NULL) == -1) {
return oserr("pledge", errno);
return oserr(NULL", errno);
}
#endif
@ -222,7 +224,7 @@ int main(int argc, char *argv[]) {
if (i == 0) { perms = "r"; }
if (unveil(optarg, perms) == -1) {
return oserr("unveil", errno);
return oserr(NULL, errno);
}
#endif
@ -266,7 +268,7 @@ int main(int argc, char *argv[]) {
}
}
#ifdef __OpenBSD__
if (unveil(NULL, NULL) == -1) { return oserr("unveil", errno); }
if (unveil(NULL, NULL) == -1) { return oserr(NULL, errno); }
#endif
assert(io->fd != STDIN_FILENO || io->fl == read_flags);