use %m printf specifier where appropriate
No binary (build failed)
—
(log yok)
| @@ -1038,7 +1038,7 @@ static void colon(char *buf) | |
| } | |
| if (cnt < 0) { | |
| if (cnt == -1) | |
| - | status_line_bold("Write error: %s", strerror(errno)); |
| + | status_line_bold("Write error: "STRERROR_FMT STRERROR_ERRNO); |
| } else { | |
| modified_count = 0; | |
| last_modified_count = -1; | |
| @@ -3131,7 +3131,7 @@ static void status_line_bold(const char *format, ...) | |
| static void status_line_bold_errno(const char *fn) | |
| { | |
| - | status_line_bold("'%s' %s", fn, strerror(errno)); |
| + | status_line_bold("'%s' "STRERROR_FMT, fn STRERROR_ERRNO); |
| } | |
| // format status buffer | |
| @@ -4066,7 +4066,7 @@ static void do_cmd(int c) | |
| cnt = file_write(current_filename, text, end - 1); | |
| if (cnt < 0) { | |
| if (cnt == -1) | |
| - | status_line_bold("Write error: %s", strerror(errno)); |
| + | status_line_bold("Write error: "STRERROR_FMT STRERROR_ERRNO); |
| } else if (cnt == (end - 1 - text + 1)) { | |
| editing = 0; | |
| } | |
| @@ -162,6 +162,17 @@ | |
| #ifndef HAVE_XTABS | |
| # define XTABS TAB3 | |
| #endif | |
| + | /* |
| + | * Use '%m' to append error string on platforms that support it, |
| + | * '%s' and strerror() on those that don't. |
| + | */ |
| + | #ifdef HAVE_PRINTF_PERCENTM |
| + | # define STRERROR_FMT "%m" |
| + | # define STRERROR_ERRNO /*nothing*/ |
| + | #else |
| + | # define STRERROR_FMT "%s" |
| + | # define STRERROR_ERRNO ,strerror(errno) |
| + | #endif |
| /* Some libc's forget to declare these, do it ourself */ | |
| @@ -391,8 +391,10 @@ static int open_stdio_to_tty(const char* tty_name) | |
| /* fd can be only < 0 or 0: */ | |
| fd = device_open(tty_name, O_RDWR); | |
| if (fd) { | |
| - | message(L_LOG | L_CONSOLE, "can't open %s: %s", |
| - | tty_name, strerror(errno)); |
| + | message(L_LOG | L_CONSOLE, "can't open %s: "STRERROR_FMT, |
| + | tty_name |
| + | STRERROR_ERRNO |
| + | ); |
| return 0; /* failure */ | |
| } | |
| dup2(STDIN_FILENO, STDOUT_FILENO); | |
| @@ -469,7 +471,7 @@ static void init_exec(const char *command) | |
| } | |
| /* Here command never contains the dash, cmd[0] might */ | |
| BB_EXECVP(command, cmd); | |
| - | message(L_LOG | L_CONSOLE, "can't run '%s': %s", command, strerror(errno)); |
| + | message(L_LOG | L_CONSOLE, "can't run '%s': "STRERROR_FMT, command STRERROR_ERRNO); |
| /* returns if execvp fails */ | |
| } | |
| @@ -1432,7 +1432,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |
| len = d6_recv_raw_packet(&srv6_buf, &packet, sockfd); | |
| if (len == -1) { | |
| /* Error is severe, reopen socket */ | |
| - | bb_error_msg("read error: %s, reopening socket", strerror(errno)); |
| + | bb_error_msg("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO); |
| sleep(discover_timeout); /* 3 seconds by default */ | |
| change_listen_mode(listen_mode); /* just close and reopen */ | |
| } | |
| @@ -1631,7 +1631,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |
| len = udhcp_recv_raw_packet(&packet, sockfd); | |
| if (len == -1) { | |
| /* Error is severe, reopen socket */ | |
| - | bb_error_msg("read error: %s, reopening socket", strerror(errno)); |
| + | bb_error_msg("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO); |
| sleep(discover_timeout); /* 3 seconds by default */ | |
| change_listen_mode(listen_mode); /* just close and reopen */ | |
| } | |
| @@ -948,7 +948,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |
| if (bytes < 0) { | |
| /* bytes can also be -2 ("bad packet data") */ | |
| if (bytes == -1 && errno != EINTR) { | |
| - | log1("read error: %s, reopening socket", strerror(errno)); |
| + | log1("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO); |
| close(server_socket); | |
| server_socket = -1; | |
| } | |
| @@ -224,7 +224,7 @@ static void out(const char *p, const char *m1) | |
| { | |
| printf("%s%s%s: %s", p, *service, islog ? "/log" : "", m1); | |
| if (errno) { | |
| - | printf(": %s", strerror(errno)); |
| + | printf(": "STRERROR_FMT STRERROR_ERRNO); |
| } | |
| bb_putchar('\n'); /* will also flush the output */ | |
| } | |
| @@ -104,7 +104,7 @@ int matchpathcon_main(int argc UNUSED_PARAM, char **argv) | |
| freecon(con); | |
| continue; | |
| } | |
| - | printf("actual context unknown: %s, should be ", strerror(errno)); |
| + | printf("actual context unknown: "STRERROR_FMT", should be " STRERROR_ERRNO); |
| error += print_matchpathcon(path, 1); | |
| } | |
| matchpathcon_fini(); | |
| @@ -1312,16 +1312,9 @@ ash_msg_and_raise_error(const char *msg, ...) | |
| } | |
| /* | |
| - | * Use '%m' to append error string on platforms that support it, '%s' and |
| - | * strerror() on those that don't. |
| - | * |
| * 'fmt' must be a string literal. | |
| */ | |
| - | #ifdef HAVE_PRINTF_PERCENTM |
| - | #define ash_msg_and_raise_perror(fmt, ...) ash_msg_and_raise_error(fmt ": %m", ##__VA_ARGS__) |
| - | #else |
| - | #define ash_msg_and_raise_perror(fmt, ...) ash_msg_and_raise_error(fmt ": %s", ##__VA_ARGS__, strerror(errno)) |
| - | #endif |
| + | #define ash_msg_and_raise_perror(fmt, ...) ash_msg_and_raise_error(fmt ": "STRERROR_FMT, ##__VA_ARGS__ STRERROR_ERRNO) |
| static void raise_error_syntax(const char *) NORETURN; | |
| static void | |