summaryrefslogtreecommitdiffstats
path: root/src/url.c
diff options
context:
space:
mode:
authorsijanec <anton@sijanec.eu>2021-04-03 23:15:48 +0200
committersijanec <anton@sijanec.eu>2021-04-03 23:15:48 +0200
commitbbf6fe2fd069ef89f73ecc3fe3ec2000833f05f4 (patch)
treef9960c7a43f7c0e1da6cb8e8656fcbda2129677a /src/url.c
parentinitial commit (diff)
downloadsear.c-bbf6fe2fd069ef89f73ecc3fe3ec2000833f05f4.tar
sear.c-bbf6fe2fd069ef89f73ecc3fe3ec2000833f05f4.tar.gz
sear.c-bbf6fe2fd069ef89f73ecc3fe3ec2000833f05f4.tar.bz2
sear.c-bbf6fe2fd069ef89f73ecc3fe3ec2000833f05f4.tar.lz
sear.c-bbf6fe2fd069ef89f73ecc3fe3ec2000833f05f4.tar.xz
sear.c-bbf6fe2fd069ef89f73ecc3fe3ec2000833f05f4.tar.zst
sear.c-bbf6fe2fd069ef89f73ecc3fe3ec2000833f05f4.zip
Diffstat (limited to '')
-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;
}