FHREADLINK(2)
π FHREADLINK(2) β the system calls manual β¨
okay so bestie, we're in System Calls Manual territory today and this one is a little niche but it slaps once you get it, i promise π«Ά
πΈ NAME πΈ
fhreadlink β read the value of a symbolic link, but likeβ¦ by file handle π
π LIBRARY π
Standard C Library (libc, -lc) β the classic, the icon, the one you already link against π
β¨ SYNOPSIS β¨
#include <sys/param.h>
#include <sys/mount.h>
int
fhreadlink(fhandle_t *fhp, char *buf, size_t bufsize);
π¦ DESCRIPTION π¦
okay so fhreadlink() is the system call that takes the contents of the symbolic link fhp and drops them straight into the buffer buf, which has size bufsiz π«
and here's the part that gets people: fhreadlink() does not append a NUL character to buf. like, at all. no null terminator, no little gift at the end π so if you're planning to treat it like a string you gotta handle that yourself, bestie. that's on you.
π RETURN VALUES π
if it works? the call returns the count of characters it placed in the buffer, slay π
if it doesn't? it returns a -1 and tucks the error code into the global variable errno so you can go look at what went wrong π
π₯ ERRORS π₯
the fhreadlink() system call will fail if any of these happen:
[ENOENT]β the named file does not exist. it's giving ~nothing~ π[ELOOP]β too many symbolic links were encountered while translating the file handlefhp. link-ception, we're not doing that today π[EINVAL]β the named file is not a symbolic link. wrong vibe entirely, not the main character you were looking for π[EIO]β an I/O error occurred while reading from the file system. the filesystem is having a moment π«[EINTEGRITY]β corrupted data was detected while reading from the file system. something is rotten and it's not the algorithm π[EFAULT]β thebufargument extends outside the process's allocated address space. you're colouring outside the lines, literally β οΈ[ESTALE]β the file handlefhpis no longer valid. expired, deceased, gone girl π
π SEE ALSO π
fhlink(2), fhstat(2), readlink(2) β go read these next, you'll be obsessed π
β HISTORY β
the fhreadlink() system call first appeared in FreeBSD 12.1 π a Scorpio, presumably.
ngl bestie, the whole "noNULat the end" thing is the number one thing to remember here. everything else is just vibes anderrnochecks π
mwah π this page came to you from Debian, dated November 30, 2022 β consider this your cute little sign-off, take care of yourself, hydrate, and check your return values π§ββοΈ
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π the page's license: BSD-2-Clause
- Copyright (c) 2018 Gandi
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms