diff options
author | sijanec <anton@sijanec.eu> | 2021-04-03 23:15:48 +0200 |
---|---|---|
committer | sijanec <anton@sijanec.eu> | 2021-04-03 23:15:48 +0200 |
commit | bbf6fe2fd069ef89f73ecc3fe3ec2000833f05f4 (patch) | |
tree | f9960c7a43f7c0e1da6cb8e8656fcbda2129677a /src/url.c | |
parent | initial commit (diff) | |
download | sear.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 'src/url.c')
-rw-r--r-- | src/url.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -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; } |