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