aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-09-29 18:17:25 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-09-29 18:17:25 +0200
commit6f97b30a904407c1f1701d937d9258ca9175c6ab (patch)
tree093a86cb555fb3e7f365cea21095a7df8d5dce77
parentf625836e6059d307e951a60b60f1c9ed259ee983 (diff)
downloadbusybox-w32-6f97b30a904407c1f1701d937d9258ca9175c6ab.tar.gz
busybox-w32-6f97b30a904407c1f1701d937d9258ca9175c6ab.tar.bz2
busybox-w32-6f97b30a904407c1f1701d937d9258ca9175c6ab.zip
use %m printf specifier where appropriate
function old new delta out 85 75 -10 udhcpd_main 1472 1461 -11 open_stdio_to_tty 98 85 -13 init_exec 245 232 -13 udhcpc_main 2763 2749 -14 do_cmd 4771 4755 -16 status_line_bold_errno 32 14 -18 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/7 up/down: 0/-95) Total: -95 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/vi.c6
-rw-r--r--include/libbb.h11
-rw-r--r--init/init.c8
-rw-r--r--networking/udhcp/d6_dhcpc.c2
-rw-r--r--networking/udhcp/dhcpc.c2
-rw-r--r--networking/udhcp/dhcpd.c2
-rw-r--r--runit/sv.c2
-rw-r--r--selinux/matchpathcon.c2
-rw-r--r--shell/ash.c9
9 files changed, 25 insertions, 19 deletions
diff --git a/editors/vi.c b/editors/vi.c
index 60c73c0eb..cdfb27cc5 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -1038,7 +1038,7 @@ static void colon(char *buf)
1038 } 1038 }
1039 if (cnt < 0) { 1039 if (cnt < 0) {
1040 if (cnt == -1) 1040 if (cnt == -1)
1041 status_line_bold("Write error: %s", strerror(errno)); 1041 status_line_bold("Write error: "STRERROR_FMT STRERROR_ERRNO);
1042 } else { 1042 } else {
1043 modified_count = 0; 1043 modified_count = 0;
1044 last_modified_count = -1; 1044 last_modified_count = -1;
@@ -3131,7 +3131,7 @@ static void status_line_bold(const char *format, ...)
3131 3131
3132static void status_line_bold_errno(const char *fn) 3132static void status_line_bold_errno(const char *fn)
3133{ 3133{
3134 status_line_bold("'%s' %s", fn, strerror(errno)); 3134 status_line_bold("'%s' "STRERROR_FMT, fn STRERROR_ERRNO);
3135} 3135}
3136 3136
3137// format status buffer 3137// format status buffer
@@ -4066,7 +4066,7 @@ static void do_cmd(int c)
4066 cnt = file_write(current_filename, text, end - 1); 4066 cnt = file_write(current_filename, text, end - 1);
4067 if (cnt < 0) { 4067 if (cnt < 0) {
4068 if (cnt == -1) 4068 if (cnt == -1)
4069 status_line_bold("Write error: %s", strerror(errno)); 4069 status_line_bold("Write error: "STRERROR_FMT STRERROR_ERRNO);
4070 } else if (cnt == (end - 1 - text + 1)) { 4070 } else if (cnt == (end - 1 - text + 1)) {
4071 editing = 0; 4071 editing = 0;
4072 } 4072 }
diff --git a/include/libbb.h b/include/libbb.h
index aff2825ac..daccf154a 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -162,6 +162,17 @@
162#ifndef HAVE_XTABS 162#ifndef HAVE_XTABS
163# define XTABS TAB3 163# define XTABS TAB3
164#endif 164#endif
165/*
166 * Use '%m' to append error string on platforms that support it,
167 * '%s' and strerror() on those that don't.
168 */
169#ifdef HAVE_PRINTF_PERCENTM
170# define STRERROR_FMT "%m"
171# define STRERROR_ERRNO /*nothing*/
172#else
173# define STRERROR_FMT "%s"
174# define STRERROR_ERRNO ,strerror(errno)
175#endif
165 176
166 177
167/* Some libc's forget to declare these, do it ourself */ 178/* Some libc's forget to declare these, do it ourself */
diff --git a/init/init.c b/init/init.c
index 64e5c3e0b..5304e5c2c 100644
--- a/init/init.c
+++ b/init/init.c
@@ -391,8 +391,10 @@ static int open_stdio_to_tty(const char* tty_name)
391 /* fd can be only < 0 or 0: */ 391 /* fd can be only < 0 or 0: */
392 fd = device_open(tty_name, O_RDWR); 392 fd = device_open(tty_name, O_RDWR);
393 if (fd) { 393 if (fd) {
394 message(L_LOG | L_CONSOLE, "can't open %s: %s", 394 message(L_LOG | L_CONSOLE, "can't open %s: "STRERROR_FMT,
395 tty_name, strerror(errno)); 395 tty_name
396 STRERROR_ERRNO
397 );
396 return 0; /* failure */ 398 return 0; /* failure */
397 } 399 }
398 dup2(STDIN_FILENO, STDOUT_FILENO); 400 dup2(STDIN_FILENO, STDOUT_FILENO);
@@ -469,7 +471,7 @@ static void init_exec(const char *command)
469 } 471 }
470 /* Here command never contains the dash, cmd[0] might */ 472 /* Here command never contains the dash, cmd[0] might */
471 BB_EXECVP(command, cmd); 473 BB_EXECVP(command, cmd);
472 message(L_LOG | L_CONSOLE, "can't run '%s': %s", command, strerror(errno)); 474 message(L_LOG | L_CONSOLE, "can't run '%s': "STRERROR_FMT, command STRERROR_ERRNO);
473 /* returns if execvp fails */ 475 /* returns if execvp fails */
474} 476}
475 477
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
index c13f23505..37ffd064d 100644
--- a/networking/udhcp/d6_dhcpc.c
+++ b/networking/udhcp/d6_dhcpc.c
@@ -1432,7 +1432,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1432 len = d6_recv_raw_packet(&srv6_buf, &packet, sockfd); 1432 len = d6_recv_raw_packet(&srv6_buf, &packet, sockfd);
1433 if (len == -1) { 1433 if (len == -1) {
1434 /* Error is severe, reopen socket */ 1434 /* Error is severe, reopen socket */
1435 bb_error_msg("read error: %s, reopening socket", strerror(errno)); 1435 bb_error_msg("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO);
1436 sleep(discover_timeout); /* 3 seconds by default */ 1436 sleep(discover_timeout); /* 3 seconds by default */
1437 change_listen_mode(listen_mode); /* just close and reopen */ 1437 change_listen_mode(listen_mode); /* just close and reopen */
1438 } 1438 }
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 4548d4ac7..0013f4aa7 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -1631,7 +1631,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1631 len = udhcp_recv_raw_packet(&packet, sockfd); 1631 len = udhcp_recv_raw_packet(&packet, sockfd);
1632 if (len == -1) { 1632 if (len == -1) {
1633 /* Error is severe, reopen socket */ 1633 /* Error is severe, reopen socket */
1634 bb_error_msg("read error: %s, reopening socket", strerror(errno)); 1634 bb_error_msg("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO);
1635 sleep(discover_timeout); /* 3 seconds by default */ 1635 sleep(discover_timeout); /* 3 seconds by default */
1636 change_listen_mode(listen_mode); /* just close and reopen */ 1636 change_listen_mode(listen_mode); /* just close and reopen */
1637 } 1637 }
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index 57d8b36c5..238542bb0 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -948,7 +948,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
948 if (bytes < 0) { 948 if (bytes < 0) {
949 /* bytes can also be -2 ("bad packet data") */ 949 /* bytes can also be -2 ("bad packet data") */
950 if (bytes == -1 && errno != EINTR) { 950 if (bytes == -1 && errno != EINTR) {
951 log1("read error: %s, reopening socket", strerror(errno)); 951 log1("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO);
952 close(server_socket); 952 close(server_socket);
953 server_socket = -1; 953 server_socket = -1;
954 } 954 }
diff --git a/runit/sv.c b/runit/sv.c
index 1d0809be8..dc5dcceb3 100644
--- a/runit/sv.c
+++ b/runit/sv.c
@@ -224,7 +224,7 @@ static void out(const char *p, const char *m1)
224{ 224{
225 printf("%s%s%s: %s", p, *service, islog ? "/log" : "", m1); 225 printf("%s%s%s: %s", p, *service, islog ? "/log" : "", m1);
226 if (errno) { 226 if (errno) {
227 printf(": %s", strerror(errno)); 227 printf(": "STRERROR_FMT STRERROR_ERRNO);
228 } 228 }
229 bb_putchar('\n'); /* will also flush the output */ 229 bb_putchar('\n'); /* will also flush the output */
230} 230}
diff --git a/selinux/matchpathcon.c b/selinux/matchpathcon.c
index e57120d3b..6945a0295 100644
--- a/selinux/matchpathcon.c
+++ b/selinux/matchpathcon.c
@@ -104,7 +104,7 @@ int matchpathcon_main(int argc UNUSED_PARAM, char **argv)
104 freecon(con); 104 freecon(con);
105 continue; 105 continue;
106 } 106 }
107 printf("actual context unknown: %s, should be ", strerror(errno)); 107 printf("actual context unknown: "STRERROR_FMT", should be " STRERROR_ERRNO);
108 error += print_matchpathcon(path, 1); 108 error += print_matchpathcon(path, 1);
109 } 109 }
110 matchpathcon_fini(); 110 matchpathcon_fini();
diff --git a/shell/ash.c b/shell/ash.c
index 3fa7f4d9f..39705a350 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -1312,16 +1312,9 @@ ash_msg_and_raise_error(const char *msg, ...)
1312} 1312}
1313 1313
1314/* 1314/*
1315 * Use '%m' to append error string on platforms that support it, '%s' and
1316 * strerror() on those that don't.
1317 *
1318 * 'fmt' must be a string literal. 1315 * 'fmt' must be a string literal.
1319 */ 1316 */
1320#ifdef HAVE_PRINTF_PERCENTM 1317#define ash_msg_and_raise_perror(fmt, ...) ash_msg_and_raise_error(fmt ": "STRERROR_FMT, ##__VA_ARGS__ STRERROR_ERRNO)
1321#define ash_msg_and_raise_perror(fmt, ...) ash_msg_and_raise_error(fmt ": %m", ##__VA_ARGS__)
1322#else
1323#define ash_msg_and_raise_perror(fmt, ...) ash_msg_and_raise_error(fmt ": %s", ##__VA_ARGS__, strerror(errno))
1324#endif
1325 1318
1326static void raise_error_syntax(const char *) NORETURN; 1319static void raise_error_syntax(const char *) NORETURN;
1327static void 1320static void