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