}
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;
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
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;
}
#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 */
/* 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);
}
/* 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 */
}
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 */
}
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 */
}
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;
}
{
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 */
}
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();
}
/*
- * 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