use %m printf specifier where appropriate
authorDenys Vlasenko <vda.linux@googlemail.com>
Fri, 29 Sep 2017 16:17:25 +0000 (18:17 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Fri, 29 Sep 2017 16:17:25 +0000 (18:17 +0200)
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>
editors/vi.c
include/libbb.h
init/init.c
networking/udhcp/d6_dhcpc.c
networking/udhcp/dhcpc.c
networking/udhcp/dhcpd.c
runit/sv.c
selinux/matchpathcon.c
shell/ash.c

index 60c73c0eba44955c6a3d32d14ba191ec11a72d6b..cdfb27cc5abeaea05daa7a8a6b7de89871cb69b6 100644 (file)
@@ -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;
                        }
index aff2825ac6395acc3cfc71ca8d0da1dd594c9e90..daccf154a339a005210f4a3bec8ff7b0ba3af1a0 100644 (file)
 #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 */
index 64e5c3e0bfb329be534c3ba0f1494714dd98d9b8..5304e5c2c068bed271df2d20f80b055d9d218b0c 100644 (file)
@@ -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 */
 }
 
index c13f23505c558bc70176565637527e61a0536966..37ffd064d67fb382a3096fcc9840ba02c4fe5298 100644 (file)
@@ -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 */
                        }
index 4548d4ac7df5e6799171516eb85dd82f37297cbb..0013f4aa795ce51ac23b46939dbdb01d2c7f9f2a 100644 (file)
@@ -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 */
                        }
index 57d8b36c5538fcf8f2799f3ddd3b7eaa5147959b..238542bb0c363e26186ae5284eb13edcf311906b 100644 (file)
@@ -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;
                        }
index 1d0809be86883b7cb4b71559e160f1e035c72ebb..dc5dcceb3b860bd40c019c79116b0615d28100b4 100644 (file)
@@ -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 */
 }
index e57120d3b9ff972af9b23690078d7ba93cc49de0..6945a029572f62dc0dc1eb14e1bb5f249189d1b9 100644 (file)
@@ -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();
index 3fa7f4d9f62cc8c76d15a4a7e63d4e7e77389b6f..39705a350aba14b95ab06b8c783bd5443a2586f2 100644 (file)
@@ -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