diff options
author | Ron Yorston <rmy@pobox.com> | 2023-02-01 11:09:05 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-02-01 11:09:05 +0000 |
commit | 6e9d680e5bd72f30eb6c8a6972b9653086e4ac90 (patch) | |
tree | 750742e4ccd5fdace24bf29a12239de1f3b98570 | |
parent | 2d848eba575c32f797cea465b1ccba27467fad45 (diff) | |
download | busybox-w32-6e9d680e5bd72f30eb6c8a6972b9653086e4ac90.tar.gz busybox-w32-6e9d680e5bd72f30eb6c8a6972b9653086e4ac90.tar.bz2 busybox-w32-6e9d680e5bd72f30eb6c8a6972b9653086e4ac90.zip |
make: strip leading whitespace in shell assignment
Assignment of shell output to a macro ('!=') was originally a
non-POSIX extension. It later became a POSIX 202X feature.
However, the implementation failed to include the additional
POSIX requirement that leading whitespace is removed from the
shell output.
Neither GNU make nor bmake strip leading whitespace. Implement
this behaviour as a non-POSIX extension.
-rw-r--r-- | miscutils/make.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/miscutils/make.c b/miscutils/make.c index 24e286aa9..fcd1e3fbe 100644 --- a/miscutils/make.c +++ b/miscutils/make.c | |||
@@ -1636,22 +1636,39 @@ run_command(const char *cmd) | |||
1636 | } | 1636 | } |
1637 | pclose(fd); | 1637 | pclose(fd); |
1638 | 1638 | ||
1639 | if (val) { | 1639 | if (val == NULL) |
1640 | #if ENABLE_PLATFORM_MINGW32 | 1640 | return NULL; |
1641 | len = remove_cr(val, len + 1) - 1; | 1641 | |
1642 | // Strip leading whitespace in POSIX 202X mode | ||
1643 | if (posix) { | ||
1644 | s = val; | ||
1645 | while (isspace(*s)) { | ||
1646 | ++s; | ||
1647 | --len; | ||
1648 | } | ||
1649 | |||
1642 | if (len == 0) { | 1650 | if (len == 0) { |
1643 | free(val); | 1651 | free(val); |
1644 | return NULL; | 1652 | return NULL; |
1645 | } | 1653 | } |
1654 | memmove(val, s, len + 1); | ||
1655 | } | ||
1656 | |||
1657 | #if ENABLE_PLATFORM_MINGW32 | ||
1658 | len = remove_cr(val, len + 1) - 1; | ||
1659 | if (len == 0) { | ||
1660 | free(val); | ||
1661 | return NULL; | ||
1662 | } | ||
1646 | #endif | 1663 | #endif |
1647 | // Remove one newline from the end (BSD compatibility) | 1664 | |
1648 | if (val[len - 1] == '\n') | 1665 | // Remove one newline from the end (BSD compatibility) |
1649 | val[len - 1] = '\0'; | 1666 | if (val[len - 1] == '\n') |
1650 | // Other newlines are changed to spaces | 1667 | val[len - 1] = '\0'; |
1651 | for (s = val; *s; ++s) { | 1668 | // Other newlines are changed to spaces |
1652 | if (*s == '\n') | 1669 | for (s = val; *s; ++s) { |
1653 | *s = ' '; | 1670 | if (*s == '\n') |
1654 | } | 1671 | *s = ' '; |
1655 | } | 1672 | } |
1656 | return val; | 1673 | return val; |
1657 | } | 1674 | } |