aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-10-18 17:14:12 -0500
committerRob Landley <rob@landley.net>2014-10-18 17:14:12 -0500
commit5fcc71581abdf8839d10786d7ac437cc5b0bf4c5 (patch)
tree4143360f7699d4b2b6f3daecf7ae36a2c625a913 /lib
parent01138b94e6ac9ff2d1258917f96c0c5c8c124021 (diff)
downloadtoybox-5fcc71581abdf8839d10786d7ac437cc5b0bf4c5.tar.gz
Factor out printf-style escape parsing logic from echo.c.
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c8
-rw-r--r--lib/lib.h1
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 19d28d2b..dc2de121 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -283,6 +283,14 @@ int stridx(char *haystack, char needle)
return off-haystack;
}
+int unescape(char c)
+{
+ char *from = "\\abefnrtv", *to = "\\\a\b\033\f\n\r\t\v";
+ int idx = stridx(from, c);
+
+ return (idx == -1) ? 0 : to[idx];
+}
+
// If *a starts with b, advance *a past it and return 1, else return 0;
int strstart(char **a, char *b)
{
diff --git a/lib/lib.h b/lib/lib.h
index 887c1d57..49b02bb5 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -152,6 +152,7 @@ long atolx(char *c);
long atolx_range(char *numstr, long low, long high);
int numlen(long l);
int stridx(char *haystack, char needle);
+int unescape(char c);
int strstart(char **a, char *b);
off_t fdlength(int fd);
void loopfiles_rw(char **argv, int flags, int permissions, int failok,