aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2017-07-27 13:53:39 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2017-07-28 15:39:26 +0200
commitbe366e5afac1d9f5b3958bd3899a389308d5d9d3 (patch)
tree60c41a15eed758d0cee5a637c063fe53eff36046 /shell
parent619d9b5e6848a72350126ea9c1e413fd133181e3 (diff)
downloadbusybox-w32-be366e5afac1d9f5b3958bd3899a389308d5d9d3.tar.gz
busybox-w32-be366e5afac1d9f5b3958bd3899a389308d5d9d3.tar.bz2
busybox-w32-be366e5afac1d9f5b3958bd3899a389308d5d9d3.zip
ash: support platforms that don't have '%m' printf specifier
The '%m' conversion specifier prints an error message based on the current value of 'errno'. It is available in the GNU C library, Cygwin (since 2012), uClibc and musl. It is not available in various BSDs, BSD-derived systems (MacOS, Android) or Microsoft Windows. Use a symbol defined in platform.h to control how error messages can be formatted to display the 'errno' message. On platforms that support it use '%m'; on other platforms use '%s' and strerror(). On platforms that have '%m' there is essentially no change in the size of the binary. Otherwise: function old new delta redirect 1287 1310 +23 xtcsetpgrp 27 44 +17 dup2_or_raise 34 51 +17 setinputfile 267 275 +8 .rodata 163379 163371 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/1 up/down: 65/-8) Total: 57 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 1f5a8dae0..f9c78ee78 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -1306,6 +1306,18 @@ ash_msg_and_raise_error(const char *msg, ...)
1306 va_end(ap); 1306 va_end(ap);
1307} 1307}
1308 1308
1309/*
1310 * Use '%m' to append error string on platforms that support it, '%s' and
1311 * strerror() on those that don't.
1312 *
1313 * 'fmt' must be a string literal.
1314 */
1315#ifdef HAVE_PRINTF_PERCENTM
1316#define ash_msg_and_raise_perror(fmt, ...) ash_msg_and_raise_error(fmt ": %m", ##__VA_ARGS__)
1317#else
1318#define ash_msg_and_raise_perror(fmt, ...) ash_msg_and_raise_error(fmt ": %s", ##__VA_ARGS__, strerror(errno))
1319#endif
1320
1309static void raise_error_syntax(const char *) NORETURN; 1321static void raise_error_syntax(const char *) NORETURN;
1310static void 1322static void
1311raise_error_syntax(const char *msg) 1323raise_error_syntax(const char *msg)
@@ -3827,7 +3839,7 @@ static void
3827xtcsetpgrp(int fd, pid_t pgrp) 3839xtcsetpgrp(int fd, pid_t pgrp)
3828{ 3840{
3829 if (tcsetpgrp(fd, pgrp)) 3841 if (tcsetpgrp(fd, pgrp))
3830 ash_msg_and_raise_error("can't set tty process group (%m)"); 3842 ash_msg_and_raise_perror("can't set tty process group");
3831} 3843}
3832 3844
3833/* 3845/*
@@ -5313,7 +5325,7 @@ savefd(int from)
5313 err = newfd < 0 ? errno : 0; 5325 err = newfd < 0 ? errno : 0;
5314 if (err != EBADF) { 5326 if (err != EBADF) {
5315 if (err) 5327 if (err)
5316 ash_msg_and_raise_error("%d: %m", from); 5328 ash_msg_and_raise_perror("%d", from);
5317 close(from); 5329 close(from);
5318 fcntl(newfd, F_SETFD, FD_CLOEXEC); 5330 fcntl(newfd, F_SETFD, FD_CLOEXEC);
5319 } 5331 }
@@ -5328,7 +5340,7 @@ dup2_or_raise(int from, int to)
5328 newfd = (from != to) ? dup2(from, to) : to; 5340 newfd = (from != to) ? dup2(from, to) : to;
5329 if (newfd < 0) { 5341 if (newfd < 0) {
5330 /* Happens when source fd is not open: try "echo >&99" */ 5342 /* Happens when source fd is not open: try "echo >&99" */
5331 ash_msg_and_raise_error("%d: %m", from); 5343 ash_msg_and_raise_perror("%d", from);
5332 } 5344 }
5333 return newfd; 5345 return newfd;
5334} 5346}
@@ -5459,7 +5471,7 @@ redirect(union node *redir, int flags)
5459 /* "echo >&10" and 10 is a fd opened to a sh script? */ 5471 /* "echo >&10" and 10 is a fd opened to a sh script? */
5460 if (is_hidden_fd(sv, right_fd)) { 5472 if (is_hidden_fd(sv, right_fd)) {
5461 errno = EBADF; /* as if it is closed */ 5473 errno = EBADF; /* as if it is closed */
5462 ash_msg_and_raise_error("%d: %m", right_fd); 5474 ash_msg_and_raise_perror("%d", right_fd);
5463 } 5475 }
5464 newfd = -1; 5476 newfd = -1;
5465 } else { 5477 } else {
@@ -5493,7 +5505,7 @@ redirect(union node *redir, int flags)
5493 if (newfd >= 0) 5505 if (newfd >= 0)
5494 close(newfd); 5506 close(newfd);
5495 errno = i; 5507 errno = i;
5496 ash_msg_and_raise_error("%d: %m", fd); 5508 ash_msg_and_raise_perror("%d", fd);
5497 /* NOTREACHED */ 5509 /* NOTREACHED */
5498 } 5510 }
5499 /* EBADF: it is not open - good, remember to close it */ 5511 /* EBADF: it is not open - good, remember to close it */