1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: curl_easy_unescape 5Section: 3 6Source: libcurl 7See-also: 8 - curl_easy_escape (3) 9 - curl_url_get (3) 10Protocol: 11 - All 12Added-in: 7.15.4 13--- 14 15# NAME 16 17curl_easy_unescape - URL decode a string 18 19# SYNOPSIS 20 21~~~c 22#include <curl/curl.h> 23 24char *curl_easy_unescape(CURL *curl, const char *input, 25 int inlength, int *outlength); 26~~~ 27 28# DESCRIPTION 29 30This function converts the URL encoded string **input** to a "plain string" 31and returns that in an allocated memory area. All input characters that are URL 32encoded (%XX where XX is a two-digit hexadecimal number) are converted to their 33binary versions. 34 35If the **length** argument is set to 0 (zero), curl_easy_unescape(3) 36uses strlen() on **input** to find out the size. 37 38If **outlength** is non-NULL, the function writes the length of the returned 39string in the integer it points to. This allows proper handling even for 40strings containing %00. Since this is a pointer to an *int* type, it can 41only return a value up to *INT_MAX* so no longer string can be returned in 42this parameter. 43 44Since 7.82.0, the **curl** parameter is ignored. Prior to that there was 45per-handle character conversion support for some old operating systems such as 46TPF, but it was otherwise ignored. 47 48You must curl_free(3) the returned string when you are done with it. 49 50# %PROTOCOLS% 51 52# EXAMPLE 53 54~~~c 55int main(void) 56{ 57 CURL *curl = curl_easy_init(); 58 if(curl) { 59 int decodelen; 60 char *decoded = curl_easy_unescape(curl, "%63%75%72%6c", 12, &decodelen); 61 if(decoded) { 62 /* do not assume printf() works on the decoded data */ 63 printf("Decoded: "); 64 /* ... */ 65 curl_free(decoded); 66 } 67 curl_easy_cleanup(curl); 68 } 69} 70~~~ 71 72# %AVAILABILITY% 73 74# RETURN VALUE 75 76A pointer to a null-terminated string or NULL if it failed. 77