CURLOPT_SEEKDATA(3)

πŸ’… CURLOPT_SEEKDATA(3) πŸ’…

ok so real talk, bestie β€” this page lives in the Library Functions Manual (that's the (3) vibe, iykyk, it's a libcurl function page) and honestly? It's a tiny one. But tiny doesn't mean skip it, because if you get this wrong your seek callback gets handed garbage and you'll be crying. Let's go. ✨


🌸 NAME 🌸

CURLOPT_SEEKDATA β€” the pointer you pass to the seek callback. That's it. That's the whole thing. A pointer. 🫢


πŸŽ€ SYNOPSIS πŸŽ€

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SEEKDATA, void *pointer);

literally three lines, she's lowkey iconic for it πŸ’…


✨ DESCRIPTION ✨

okay so picture this: this is the data pointer that gets passed to your seek callback function. That's the whole concept. It's the little bag of stuff you hand off so your callback knows what it's working with.

And the way it works is β€” if you're also using the CURLOPT_SEEKFUNCTION(3) option, this is the pointer you get as input. So like, SEEKFUNCTION is the function, SEEKDATA is the stuff you shove into it. They're a matching set, a duo, main character energy together πŸ”₯


πŸ‘‘ DEFAULT πŸ‘‘

If you do not set this, NULL is passed to the callback. No data for you. Empty hands. πŸ’€


🌈 PROTOCOLS 🌈

This functionality affects ftp, http and sftp. Those three. That's the guest list. πŸ¦‹


πŸ“ EXAMPLE πŸ“

ok bestie this example is actually so good, look at it:

#include <unistd.h> /* for lseek() */

struct data {
  int our_fd;
};

static int seek_cb(void *clientp, curl_off_t offset, int origin)
{
  struct data *d = (struct data *)clientp;
  lseek(d->our_fd, offset, origin);
  return CURL_SEEKFUNC_OK;
}

int main(void)
{
  struct data seek_data;
  CURL *curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_SEEKFUNCTION, seek_cb);
    curl_easy_setopt(curl, CURLOPT_SEEKDATA, &seek_data);
  }
}

see how seek_cb casts clientp straight back into struct data *? that's the exact pointer you handed over with CURLOPT_SEEKDATA. round trip. no cap. 🧚 And yeah, note that #include <unistd.h> is there /* for lseek() */ β€” keep your comments, they're doing the lord's work.


πŸ’– AVAILABILITY πŸ’–

Added in curl 7.18.0. Baby girl is a legend at this point. πŸ‘‘


😭 RETURN VALUE 😭

bestie the original page has nothing under this heading. Not a typo, not me skipping it β€” it's genuinely blank in the source. So like… nothing to report. πŸ™ˆ

πŸ’œ SEE ALSO πŸ’œ


and that's the whole page, fr fr. shoutout to libcurl, dated 2026-10-12 β€” she was written, she was shipped, and now you know what CURLOPT_SEEKDATA does. go forth and pass your pointers correctly, bestie πŸŽ€πŸ«Άβœ¨

πŸ“¦ where this page comes from