curl_escape(3)

πŸ’… curl_escape(3) β€” the URL-encode-a-string era πŸ’…

okay bestie, so this is a page from the Library Functions Manual about curl_escape(3), and I need you to know upfront: this one is a vintage icon. It still slays but it's retired-ish. Let's get into it πŸŽ€


✨ NAME ✨

curl_escape β€” URL encode a string πŸ¦‹

✨ SYNOPSIS ✨

#include <curl/curl.h>

char *curl_escape(const char *string, int length);

✨ DESCRIPTION ✨

okay so first things first: obsolete function. Use curl_easy_escape(3) instead. That's the vibe. This one is the older sibling that still works but everyone's like "girl, get with the program" 😭

This function converts the given input string to a URL encoded string and returns that as a new allocated string. Anything that isn't a-z, A-Z or 0-9 gets converted to its "URL escaped" version β€” that's %NN where NN is a two-digit hexadecimal number. πŸ’…

lowkey important: although it's not constrained by its type, the returned string may not be altered. Like, look, don't touch. πŸ™ˆ

If the length argument is set to 0, curl_escape(3) uses strlen() on string to find out the size. cute little shortcut ✨

You must curl_free(3) the returned string when you're done with it. No leaking, bestie, that's not the moment. 🫢

✨ PROTOCOLS ✨

This functionality affects all supported protocols 🌈 (yes, all of them, it's giving versatility)

✨ EXAMPLE ✨

here's the moment, the main character code block πŸ‘‘

int main(void)
{
  char *output = curl_escape("data to convert", 15);
  if(output) {
    printf("Encoded: %s\n", output);
    curl_free(output);
  }
}

✨ HISTORY ✨

Since 7.15.4, curl_easy_escape(3) should be used. πŸ”₯

and heads up: this function might be removed in a future release. like, it's on the clock, ngl πŸ’€

✨ AVAILABILITY ✨

Added in curl 7.1 ⭐ (ancient, iconic, historic)

✨ RETURN VALUE ✨

A pointer to a null-terminated string β€” or NULL if it failed. 😭 (bestie, check for the NULL, fr fr)

✨ SEE ALSO ✨


and that's the whole page, no cap πŸ’– this little gem lives in libcurl, dated 2026-10-12 β€” mwah, go free your strings and stay encoded πŸ§šβ€β™€οΈβœ¨

πŸ“¦ where this page comes from