FREEBSD::STRINGF(3)
hiii bestie!! welcome to the FREEBSD::STRINGF(3) page from the Library Functions Manual β today's main character is freebsd::fd_up, and it's literally a tiny owner for a file descriptor. π
β¨
πΈ NAME πΈ
freebsd::fd_up β own a file descriptor. that's it, that's the vibe: it owns a file descriptor, periodt. π«Ά
π LIBRARY π
library βlibutil++β β yes bestie, that's the library. π
β¨ SYNOPSIS β¨
okay so first you include this header, no cap:
#include <libutil++.hh>
then the class looks like this β every signature stays exactly as written:
class freebsd::fd_up
{
fd_up();
fd_up(int fd);
fd_up(fd_up &&other);
~fd_up();
int
get();
int
release();
void
reset(int newfd = -1);
fd_up &
operator=(fd_up &&other);
fd_up &
operator=(int fd);
explicit operator bool();
operator int();
};
π¦ DESCRIPTION π¦
each instance of this class owns a file descriptor. lowkey iconic. this class is patterned on std::unique_ptr, but instead of owning a pointer to an object, this class owns a file descriptor. the currently-owned file descriptor is disposed by invoking close(2) when an instance of this class is destroyed. the currently-owned file descriptor is also disposed if it is replaced by the reset() method or assignment operators. πβ¨
get()β returns the current file descriptor value while retaining ownership. iykyk. πrelease()β relinquishes ownership of the current file descriptor and returns the value of the previously-owned file descriptor. slay. πexplicit operator bool()β this explicit bool conversion operator permits testing the validity of an object. the operator returnstrueif the instance owns a valid file descriptor. vibe check passed. βoperator int()β this implicit int conversion operator permits passing an instance of this class directly as an argument to existing functions which expect a file descriptor. main character energy fr fr. π
π EXAMPLES π
freebsd::fd_up fd(open("/dev/null", O_RDWR));
if (!fd)
err(1, "open");
write(fd, "test", 4);
// `fd' is implicitly closed on destruction
not me showing you the whole little example β obsessed. the comment says it all: fd gets implicitly closed on destruction. π
π SEE ALSO π
close(2) β go read it, bestie. π«Ά
xoxo, this page came from Debian on July 31, 2025, for FREEBSD::STRINGF(3) πβ¨
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π the page's license: BSD-2-Clause
- Copyright (c) 2025 Chelsio Communications, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms