FBB::IFdBuf(3bobcat)

πŸ’… FBB::IFdBuf β€” from the 3bobcat manual, bestie edition πŸ¦‹

okay so welcome to the glow-up of the FBB::IFdBuf page β€” it lives in the bobcat manual (section 3bobcat), and it's all about the File Descriptor Input Stream Buffer. yes that's the whole vibe. let's get into it ✨


✨ NAME ✨

FBB::IFdBuf β€” an input stream buffer that gets initialized by a file descriptor. literally that's it, that's the girl πŸŽ€


🌸 SYNOPSIS 🌸

#include <bobcat/ifdbuf> (when using FBB::IFdBuf
#include <bobcat/ifdbufs> (when using FBB::IFdBufS

Linking option: -lbobcat


πŸ’– DESCRIPTION πŸ’–

FBB::IFdBuf objects can be used as a std::streambuf for std::istream objects, which is the whole reason you can do extractions straight from a file descriptor. main character energy tbh.

FBB::IFdBufS objects work exactly like FBB::IFdBuf objects, BUT β€” and this is the plot twist β€” they use FBB::Selector objects to check whether there's actually info available on the object's file descriptor before reading from it. so it's the patient, polite, waits-its-turn version 🫢

heads up bestie: file descriptors are not defined inside the C++ context. they can be used on operating systems that support the concept, but using them drags in operating system dependencies. it's giving portability concerns, so know what you're signing up for πŸ’€

🧚 NAMESPACE 🧚

FBB

Every constructor, member, operator and manipulator mentioned in this man-page is defined in the namespace FBB. all of them. no stragglers ✨


πŸ‘‘ INHERITS FROM πŸ‘‘

std::streambuf

she's a nepo baby and she earned it πŸ’…


🌈 ENUMERATION 🌈

The public enumeration Mode, defined in the class FBB::IFdStreamBuf, has these values:

  • CLOSE_FD β€” says the file descriptor used by the object must be closed.
  • KEEP_FD β€” this is the default, and it says the file descriptor used by the object must not be closed.

πŸŽ€ CONSTRUCTORS πŸŽ€

  • IFdBuf() β€” initializes the streambuf, does not associate it with a file descriptor, and uses no buffering. afterwards you can call the member reset to hook the object up to a file descriptor and optionally a buffer size. when the object gets destroyed, or when the mode-less overloaded version of the reset member is called, the file descriptor is not closed. commitment issues, respectfully πŸ™ˆ
  • IFdBuf(Mode mode) β€” same opening move: initializes the streambuf, no file descriptor association, no buffering. reset can then associate the object with a file descriptor and optionally a buffer size. but here's the difference β€” when the object is destroyed, or when the mode-less overloaded version of reset is called, the Mode argument decides whether the file descriptor gets closed or stays open. she consults the mode first, periodt.
  • IFdBuf(int fd, size_t n = 1) β€” initializes the streambuf and associates it with file descriptor fd, plus an optional unget buffer size (default size is 1). when the object is destroyed, or when the mode-less overloaded version of reset is called, the file descriptor is not closed.
  • IFdBuf(int fd, Mode mode, size_t n = 1) β€” initializes the streambuf, associates it with file descriptor fd, plus an optional unget buffer size (default size is 1). when the object is destroyed, or when the mode-less overloaded version of reset is called, the Mode argument decides whether the file descriptor gets closed or stays open.
  • IFdBufS constructors β€” to construct the corresponding IFdBufS objects, use the IFdBufS constructors that correspond to the IFdBuf constructors. matching set, no notes πŸ’–
also: copy and move constructors (and assignment operators) are not available. she does not do duplicates, she does not do relocation. not me being un-copyable 🫢

πŸ“ MEMBER FUNCTIONS πŸ“

All members of std::streambuf are available, since FBB::IFdBuf(S) inherits from that class. everything in the family tree, you get it all.

  • void close() β€” closes the file descriptor used by the IFdBuf(S), irrespective of the Mode that was specified when the IFdBuf(S) object was constructed. so even if you said KEEP_FD, this overrides it. after close, the IFdBuf(S) object can no longer be used until one of its reset members has been called. she's done until further notice πŸ’€
  • int fd() const β€” returns the file descriptor used by the IFdBuf(S) object. if the OFdBuf is not associated with a file descriptor, -1 is returned. (yes, they wrote OFdBuf here, -1 is the answer, moving on 😭)
  • void reset(int fd, size_t n = 1) β€” (re)initializes the streambuf using file descriptor fd, plus an optional unget buffer size (default size 1). when called repeatedly, the Mode specification used when the object was constructed decides whether the file descriptor gets closed or stays open. she remembers what you told her at construction time, iykyk.
  • void reset(int fd, Mode mode, size_t n = 1) β€” (re)initializes the streambuf using file descriptor fd, a file descriptor closing parameter, and an optional unget buffer size (default size 1). depending on the Mode argument, the object's currently used file descriptor will be closed or will remain open when the IFdBuf(S) object is destroyed.

⭐ EXAMPLE ⭐

#include <unistd.h>

#include <istream>
#include <iostream>

#include <bobcat/ifdbuf>

using namespace std;
using namespace FBB;

int main(int argc, char **argv)
{
                           // define a streambuf of 20 or argv[1] characters
    IFdBuf buf{ STDIN_FILENO, argc == 1 ? 20 : stoul(argv[1]) };

    istream in{ &buf };

    cout << in.rdbuf();
}

πŸ¦‹ FILES πŸ¦‹

  • bobcat/ifdbuf β€” defines the FBB::IFdBuf class interface
  • bobcat/ifdbufs β€” defines the FBB::IFdBufS class interface

πŸ’œ SEE ALSO πŸ’œ

bobcat(7), ifdstream(3bobcat), ofdbuf(3bobcat), std::streambuf


πŸ’€ BUGS πŸ’€

the member xsgetn(char *dest, std::streamsize n) sets istream::good() to false when fewer bytes than n were read using istream::read(). also see xsgetn's description. so like, heads up 🌸

another thing: by default the provided file descriptors remain open. and the complementary class ofdbuf(3bobcat)? by default it closes the file descriptor. the two of them are opposites, no cap πŸ™ˆ

🌟 BOBCAT PROJECT FILES 🌟

Debian Bobcat project files:

  • libbobcat6 β€” debian package containing the shared library, changelog and copyright note;
  • libbobcat-dev β€” debian package containing the static library, headers, manual pages, and developer info;

πŸ‘‘ BOBCAT πŸ‘‘

Bobcat is an acronym of Brokken's Own Base Classes And Templates. iconic name origin, honestly πŸŽ€


This is free software, distributed under the terms of the GNU General Public License (GPL). free as in freedom bestie ✨


🌸 AUTHOR 🌸

Frank B. Brokken (f.b.brokken@rug.nl).


and that's the whole page, bestie β€” brought to you by libbobcat-dev_6.15.01, dated 2005-2026, and yes this was FBB::IFdBuf(3bobcat) the entire time. slay, drink water, close your file descriptors responsibly πŸ’…πŸ«Ά

πŸ“¦ where this page comes from