summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2016-02-28 17:32:03 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2016-02-28 17:32:03 +0100
commit029bb88fc7244b2281b1a26b19d34c4e2ea12769 (patch)
treea15c816f6d94b9999cdd722da005d74d069a0eb1
parent9844e6c5931ec7677ca2d7cf34327ef3ff43224c (diff)
util: simplify encodehex, use inline
-rw-r--r--util.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/util.c b/util.c
index 3550310..a346905 100644
--- a/util.c
+++ b/util.c
@@ -26,15 +26,6 @@ pledge(const char *promises, const char *paths[])
}
#endif
-static void
-encodehex(unsigned char c, char *s)
-{
- static const char *table = "0123456789ABCDEF";
-
- s[0] = table[((c - (c % 16)) / 16) % 16];
- s[1] = table[c % 16];
-}
-
int
parseuri(const char *s, struct uri *u, int rel)
{
@@ -172,6 +163,7 @@ absuri(const char *link, const char *base, char *buf, size_t bufsiz)
int
encodeuri(const char *s, char *buf, size_t bufsiz)
{
+ static const char *table = "0123456789ABCDEF";
size_t i, b;
if (!bufsiz)
@@ -183,8 +175,8 @@ encodeuri(const char *s, char *buf, size_t bufsiz)
if (b + 3 >= bufsiz)
return -1;
buf[b++] = '%';
- encodehex(s[i], &buf[b]);
- b += 2;
+ buf[b++] = table[((uint8_t)s[i] >> 4) & 15];
+ buf[b++] = table[(uint8_t)s[i] & 15];
} else {
if (b >= bufsiz)
return -1;