diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-07-04 12:43:57 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-07-04 13:42:06 +0200 |
commit | 6623b1fe4df1e2fceb27eff286a86cf36809b2bc (patch) | |
tree | 95dce50157ca3f79e3fdcfae901a124660f20e93 /lib/tar/urldecode.c | |
parent | 56c1be44b5f77b067994a6f8f6ef2b397d7acadc (diff) |
libtar: add support for xattr extensions
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/tar/urldecode.c')
-rw-r--r-- | lib/tar/urldecode.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/tar/urldecode.c b/lib/tar/urldecode.c new file mode 100644 index 0000000..ac03f10 --- /dev/null +++ b/lib/tar/urldecode.c @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +#include "internal.h" + +static int xdigit(int x) +{ + if (isupper(x)) + return x - 'A' + 0x0A; + if (islower(x)) + return x - 'a' + 0x0A; + return x - '0'; +} + +void urldecode(char *str) +{ + unsigned char *out = (unsigned char *)str; + char *in = str; + int x; + + while (*in != '\0') { + x = *(in++); + + if (x == '%' && isxdigit(in[0]) && isxdigit(in[1])) { + x = xdigit(*(in++)) << 4; + x |= xdigit(*(in++)); + } + + *(out++) = x; + } + + *out = '\0'; +} |