version 1.204, 2021/03/29 03:34:52 |
version 1.205, 2021/08/31 09:51:25 |
|
|
|
|
if (str == NULL) |
if (str == NULL) |
return NULL; |
return NULL; |
if ((ret = malloc(strlen(str)+1)) == NULL) |
if ((ret = malloc(strlen(str) + 1)) == NULL) |
err(1, "Can't allocate memory for URL decoding"); |
err(1, "Can't allocate memory for URL decoding"); |
for (i = 0, reallen = 0; str[i] != '\0'; i++, reallen++, ret++) { |
for (i = 0, reallen = 0; str[i] != '\0'; i++, reallen++, ret++) { |
c = str[i]; |
c = str[i]; |
|
|
/* Cannot use strtol here because next char |
/* Cannot use strtol here because next char |
* after %xx may be a digit. |
* after %xx may be a digit. |
*/ |
*/ |
if (c == '%' && isxdigit((unsigned char)str[i+1]) && |
if (c == '%' && isxdigit((unsigned char)str[i + 1]) && |
isxdigit((unsigned char)str[i+2])) { |
isxdigit((unsigned char)str[i + 2])) { |
*ret = hextochar(&str[i+1]); |
*ret = hextochar(&str[i + 1]); |
i+=2; |
i += 2; |
continue; |
continue; |
} |
} |
*ret = c; |
*ret = c; |
} |
} |
*ret = '\0'; |
*ret = '\0'; |
|
|
return ret-reallen; |
return ret - reallen; |
} |
} |
|
|
static char * |
static char * |