GNURLOPT_WRITEDATA(3)
π GNURLOPT_WRITEDATA(3) β the glow-up edition π
ok so real talk, this page lives in the gnurl manual (the curl_easy_setopt options corner of it), and it's about that one little pointer bestie. let's get into it β¨
πΈ NAME πΈ
CURLOPT_WRITEDATA β the custom pointer you pass to the write callback, no cap π«Ά
β¨ SYNOPSIS β¨
#include <gnurl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_WRITEDATA, void *pointer);
π DESCRIPTION π
okay so picture this: it's just a data pointer, right? but it gets handed straight to the write callback. and if you're using the CURLOPT_WRITEFUNCTION(3) option, this is literally the pointer you'll get in that callback's 4th argument π that's the whole vibe.
but if you're not using a write callback? then you must make pointer a FILE * (cast to void *), because libcurl will pass it to fwrite(3) when it's writing data. that's not optional, bestie, that's the rule π
and the internal CURLOPT_WRITEFUNCTION(3) will write the data to the FILE * you gave it with this option β or to stdout if you haven't set this option at all. easy.
π win32 DLL girlies listen up: if you're using libcurl as a win32 DLL, you MUST use a CURLOPT_WRITEFUNCTION(3) if you set this option, otherwise you will experience crashes. not a vibe. not a drill. π
π DEFAULT π
by default, this is a FILE * to stdout. that's it, that's the default.
π¦ PROTOCOLS π¦
used for all protocols, periodt π
π EXAMPLE π
so the classic iconic technique? use the write callback to store the incoming data into a dynamically growing allocated buffer, and then this CURLOPT_WRITEDATA(3) is used to point to a struct or the buffer to store data in. literally main character energy β¨ like in the getinmemory example:
https://curl.haxx.se/libcurl/c/getinmemory.html
π AVAILABILITY π
available in all libcurl versions, no gatekeeping πΈ this option was formerly known as CURLOPT_FILE, and the name CURLOPT_WRITEDATA(3) was introduced in 7.9.7 β so she's been around a minute π
β RETURN VALUE β
this will return CURLE_OK. short, sweet, slay.
π₯ SEE ALSO π₯
and that's the whole page, bestie π§π β brought to you by libcurl 7.37.0, dated 16 Jun 2014, from the gnurl curl_easy_setopt options fam. iykyk π«Ά
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms