summaryrefslogtreecommitdiffstats
path: root/src/url.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/url.c')
-rw-r--r--src/url.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/url.c b/src/url.c
index a3a29e7..df93138 100644
--- a/src/url.c
+++ b/src/url.c
@@ -1,5 +1,5 @@
-int urlencode (char * o, char * i /* o must have at least strlen(i)*3+1 bytes of memory allocated */) {
- size_t written = 0;
+int urlencode (char * o, const char * i /* o must have at least strlen(i)*3+1 bytes of memory allocated */) {
+ size_t written = 0; /* o CANNOT be equal to i, unlike in urldecode */
for (; *i; i++) {
if (isalnum(*i) || *i == '.' || *i == '_' || *i == '-' || *i == '~') {
o[written++] = *i;
@@ -8,10 +8,11 @@ int urlencode (char * o, char * i /* o must have at least strlen(i)*3+1 bytes of
written += 3;
}
}
+ o[written++] = '\0';
return 1;
}
-int urldecode (char * o, char * i /* o must have at least strlen(i)+1 bytes memory allocated */) {
- size_t written = 0;
+int urldecode (char * o, const char * i /* o must have at least strlen(i)+1 bytes memory allocated */) {
+ size_t written = 0; /* o can be equal to i for decoding in-place */
char buf[] = "00";
for (; *i; i++) {
if (*i == '%') {
@@ -26,5 +27,6 @@ int urldecode (char * o, char * i /* o must have at least strlen(i)+1 bytes memo
o[written++] = *i;
}
}
+ o[written++] = '\0';
return 1;
}