FHREADLINK(2)

okay so bestie, welcome to FHREADLINK(2), a real one from the System Calls Manual section 2. yes it's a syscall page. yes it's about reading symbolic links. yes we're gonna have fun with it. ✨


🌸 NAME 🌸

fhreadlink β€” read value of a symbolic link


πŸŽ€ LIBRARY πŸŽ€

Standard C Library (libc, -lc)

like, that's where it lives. you link -lc and you're in. 🫢


✨ SYNOPSIS ✨

#include <sys/param.h>
#include <sys/mount.h>

int
fhreadlink(fhandle_t *fhp, char *buf, size_t bufsize);

look at her. three args, one int return, two headers. no notes. πŸ‘‘


πŸ’… DESCRIPTION πŸ’…

The fhreadlink() system call places the contents of the symbolic link fhp in the buffer buf, which has size bufsiz.

(and yes, bestie, we said bufsiz up there and bufsize in the synopsis. that's literally how the page is written. iconic of it, honestly. πŸ’€)

The fhreadlink() system call does not append a NUL character to buf. no cap. so like, don't go treating that buffer as a C string unless you're adding your own terminator, because she will not do it for you. 🚫


πŸ”₯ RETURN VALUES πŸ”₯

The call returns the count of characters placed in the buffer if it succeeds, or a -1 if an error occurs, placing the error code in the global variable errno.

so: positive-ish number of chars = slay. -1 = check errno, bestie. 😭


😀 ERRORS 😀

The readlink() system call will fail if:

  • [ENOENT] β€” The named file does not exist. it's giving "girl where". πŸ™ˆ
  • [ELOOP] β€” Too many symbolic links were encountered in translating the file handle fhp. a loop of links. an ouroboros of links. we are NOT doing that today. πŸŒ€
  • [EINVAL] β€” The named file is not a symbolic link. wrong vibe entirely. not a symlink, not our problem. πŸ’€
  • [EIO] β€” An I/O error occurred while reading from the file system. the disk said "not right now". 😭
  • [EINTEGRITY] β€” Corrupted data was detected while reading from the file system. the data is lying to you, do not trust her. 🚩
  • [EFAULT] β€” The buf argument extends outside the process's allocated address space. your pointer wandered off the map, bestie. πŸ—ΊοΈ
  • [ESTALE] β€” The file handle fhp is no longer valid. expired. stale. like that one situationship. πŸ“
(also yes, the page literally says "The readlink() system call will fail if:" up there even though we're all here for fhreadlink(). we don't ask questions, we just report the facts. 🫑)

πŸ‘€ SEE ALSO πŸ‘€

fhstat(2), fhlink(2),

(trailing comma included because I am nothing if not faithful to the source. periodt. πŸ’…)


🌈 the cute sign-off 🌈

this page came to you courtesy of Debian, dated March 30, 2020, and it's filed under FHREADLINK(2) in the System Calls Manual. that's the whole footer, bestie, and I have delivered it with love. go read some symlinks. πŸ’–πŸ¦‹βœ¨

πŸ“¦ where this page comes from