FREEBSD::STRINGF(3)

πŸ“¦ version 15.1, in freebsd 15.1

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 returns true if 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms