CURLOPT_NETRC_FILE(3)

πŸ’… CURLOPT_NETRC_FILE(3) πŸ’…

okay so this is a page from the libcurl Library Functions Manual, and today's main character is CURLOPT_NETRC_FILE(3) β€” like, the whole page, bestie. buckle up πŸŽ€


✨ NAME ✨

CURLOPT_NETRC_FILE β€” the filename you wanna read your .netrc info from πŸ—‚οΈ


✨ SYNOPSIS ✨

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_NETRC_FILE, char *file);

✨ DESCRIPTION ✨

so basically you pass a char pointer as the parameter, and that pointer points at a null-terminated string holding the full path name to the file you want libcurl to use as its .netrc file. path girlies rise 🫢

and like β€” if you don't set this option, but CURLOPT_NETRC(3) is set? then libcurl goes looking for a .netrc file in the current user's home directory. lowkey a scavenger hunt πŸ•΅οΈβ€β™€οΈ

the application does not have to keep the string around after setting this option. so you can let it go, bestie, it's free πŸ’…

if you use this option multiple times, the last set string overrides the previous ones, no cap. and if you set it to NULL, you disable its use again. the audacity, honestly 😭


✨ DEFAULT ✨

NULL

(yeah. nothing. empty. the void. πŸ•³οΈ)


✨ PROTOCOLS ✨

this functionality affects all supported protocols β€” every single one, she's versatile like that 🌈✨


✨ EXAMPLE ✨

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/");
    curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
    curl_easy_setopt(curl, CURLOPT_NETRC_FILE, "/tmp/magic-netrc");
    result = curl_easy_perform(curl);
  }
}

it's giving /tmp/magic-netrc and honestly? iconic name choice. main character file energy πŸ‘‘πŸ”₯


✨ HISTORY ✨

okay so lore time πŸ¦‹ β€” the CURL_NETRC_* enums became long types in 8.13.0. prior to that version, a long cast was necessary when passed to curl_easy_setopt(3). so if you're out here reading old code and wondering why the cast is there, now you know πŸ’€ iykyk


✨ AVAILABILITY ✨

Added in curl 7.11.0 ⭐ (elder. veteran. she's been here. πŸ’œ)


✨ RETURN VALUE ✨

curl_easy_setopt(3) returns a CURLcode indicating success or error, fr fr.

CURLE_OK (0) means everything was OK πŸŽ€ β€” non-zero means an error occurred, and you should go check libcurl-errors(3) to find out what went wrong 😭


✨ SEE ALSO ✨


⚠️ quick vibe check: this page is the libcurl manual, dated 2026-10-12, and it's the CURLOPT_NETRC_FILE(3) page you're looking at. remember the golden rule β€” the .netrc path is a full path, and NULL turns the whole thing off again 🫢

k that's the whole page, bestie. you ate. go set some options βœ¨πŸŒΈπŸ’–

πŸ“¦ where this page comes from