file_util: implement urldecode_path()
[oweals/opkg-lede.git] / libopkg / file_util.c
index 759c21b3ae76d206f717022c38dc8538fecf0d52..61ff736cd2c82a224cb10f48d14532b8224bd792 100644 (file)
@@ -395,3 +395,23 @@ char *urlencode_path(const char *filename)
 
        return (char *)copy;
 }
+
+char *urldecode_path(const char *filename)
+{
+       unsigned char *copy = (unsigned char *)xstrdup(filename);
+       unsigned char *in, *out;
+
+       for (in = copy, out = copy; *in != 0; in++) {
+               if (*in == '%' && isxdigit(in[1]) && isxdigit(in[2])) {
+                       *out++ = hex2bin(in[1]) * 16 + hex2bin(in[2]);
+                       in += 2;
+               }
+               else {
+                       *out++ = *in;
+               }
+       }
+
+       *out = 0;
+
+       return (char *)copy;
+}