CURLOPT_CONV_FROM_UTF8_FUNCTION(3)
π CURLOPT_CONV_FROM_UTF8_FUNCTION(3) π
okay so bestie, welcome to the libcurl Library Functions Manual, and lemme tell you, this one's a deep cut π«Ά β it's all about converting data from UTF8 to host encoding. Yes, that's a whole vibe. Let's get into it β¨
β¨ NAME β¨
CURLOPT_CONV_FROM_UTF8_FUNCTION β convert data from UTF8 to host encoding π
π¦ SYNOPSIS π¦
#include <curl/curl.h>
CURLcode conv_callback(char *ptr, size_t length);
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CONV_FROM_UTF8_FUNCTION,
conv_callback);
πΈ DESCRIPTION πΈ
So you pass a pointer to your callback function, and that function has to match the prototype up there π β like, exactly, no improvising, bestie.
This one applies to non-ASCII platforms only, iykyk. Also! curl_version_info(3) returns the CURL_VERSION_CONV feature bit set if this option is provided. Cute, right? β
Here's the deal with the data: the stuff you're converting lives in a buffer, and the ptr parameter points at it. How much data you're converting? That's the length parameter. And the converted data overlays the input data in that same buffer pointed to by ptr β in-place glow-up, no new buffer needed π
. You must return CURLE_OK when the conversion works out. If something goes wrong, return a CURLcode value defined by curl.h, like CURLE_CONV_FAILED.
CURLOPT_CONV_FROM_UTF8_FUNCTION(3) converts to host encoding from UTF8 encoding. And ngl, it's only required for SSL processing. That's it. That's the whole job π
If you set the callback pointer to NULL, or you just... don't set it at all (honestly valid), then the built-in libcurl iconv functions get used. But β and this is the plot twist π β if HAVE_ICONV was not defined when libcurl was built, and no callback has been established, then the conversion returns the CURLE_CONV_REQD error code.
If HAVE_ICONV is defined, then CURL_ICONV_CODESET_OF_HOST must also be defined. Like, for example:
#define CURL_ICONV_CODESET_OF_HOST "IBM-1047"
The iconv code in libcurl defaults the network and UTF8 codeset names like this:
#define CURL_ICONV_CODESET_OF_NETWORK "ISO8859-1"
#define CURL_ICONV_CODESET_FOR_UTF8 "UTF-8"
And if those are different on your system? You need to override these definitions. No cap, just do it π₯
π§ DEFAULT π§
NULL
π PROTOCOLS π
This functionality affects all supported protocols π
π EXAMPLE π
static CURLcode my_conv_from_utf8_to_ebcdic(char *buffer, size_t length)
{
int rc = 0;
/* in-place convert 'buffer' from UTF-8 to EBCDIC */
if(rc == 0) {
/* success */
return CURLE_OK;
}
else {
return CURLE_CONV_FAILED;
}
}
int main(void)
{
CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_CONV_FROM_UTF8_FUNCTION,
my_conv_from_utf8_to_ebcdic);
}
π DEPRECATED π
Not available and deprecated since 7.82.0. Yeah. She's retired π
Also, it was only ever available if CURL_DOES_CONVERSIONS was defined when libcurl was built.
β AVAILABILITY β
Added in curl 7.15.4 β a true vintage icon π
π«Ά RETURN VALUE π«Ά
curl_easy_setopt(3) returns a CURLcode indicating success or error.
CURLE_OK (that's 0) means everything was OK π and non-zero means an error occurred β check libcurl-errors(3) for the deets.
πΈ SEE ALSO πΈ
k that's the whole page, bestie!! π
β¨ this lil slice of libcurl manual magic is from the libcurl source, dated 2026-10-12 β mwah, go convert something, ily ππ¦π
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms