aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/echo.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-08-17 19:53:56 -0700
committerRob Landley <rob@landley.net>2019-08-19 11:23:41 -0500
commit81518f643d4d53b035b2cefbce25f06bd3cb5079 (patch)
tree9420219c83f68c0345b770a31d7958dc1eb6295a /toys/posix/echo.c
parentaa88ba047fa4210c03c3ad1168f84261167c3644 (diff)
downloadtoybox-81518f643d4d53b035b2cefbce25f06bd3cb5079.tar.gz
echo/printf: expand test cases, fix \x corner cases.
The behavior with "\xAV" (where the second hex digit is invalid) is different from the behavior with "\xVA", and echo and printf differ from each other.
Diffstat (limited to 'toys/posix/echo.c')
-rw-r--r--toys/posix/echo.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/toys/posix/echo.c b/toys/posix/echo.c
index 94546ecd..70f4ce5e 100644
--- a/toys/posix/echo.c
+++ b/toys/posix/echo.c
@@ -51,7 +51,7 @@ void echo_main(void)
// Should we output arg verbatim?
- if (!(toys.optflags & FLAG_e)) {
+ if (!FLAG(e)) {
xprintf("%s", arg);
continue;
}
@@ -79,7 +79,13 @@ void echo_main(void)
if (temp>='a' && temp<='f') {
out = (out*16)+temp-'a'+10;
c++;
- } else break;
+ } else {
+ if (n==1) {
+ --c;
+ out = '\\';
+ }
+ break;
+ }
}
}
// Slash in front of unknown character, print literal.
@@ -90,5 +96,5 @@ void echo_main(void)
}
// Output "\n" if no -n
- if (!(toys.optflags&FLAG_n)) putchar('\n');
+ if (!FLAG(n)) putchar('\n');
}