LIBSTDBUF(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’… libstdbuf(3) β€” Library Functions Manual ✨

okay so picture this: a little library named libstdbuf, and its whole ~main character~ job is to change how standard input, standard output and standard error get buffered at startup. That's it. That's the gig. πŸ‘‘


🌸 NAME 🌸

libstdbuf β€” a preloaded library to change standard streams' initial buffering. no cap, that's literally the entire name section, she's concise πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So the libstdbuf library is meant to be preloaded using the LD_PRELOAD environment variable β€” preloading it is the whole way it does its thing β€” so that it can change the initial buffering of the standard input, standard output, and standard error streams. ✨

Now, you can load and configure this library manually if you're feeling ✨manual✨ about it, but there's also a utility β€” stdbuf(1) β€” that runs a command with the appropriate environment variables already set up for you. So like, that's the easy button. 🫢


πŸŽ€ ENVIRONMENT πŸŽ€

Each stream gets configured independently through its own environment variable (and the values are defined right below, don't worry bestie):

  • _STDBUF_I β€” the initial buffering definition for the standard input stream πŸ’–
  • _STDBUF_O β€” the initial buffering definition for the standard output stream πŸ’œ
  • _STDBUF_E β€” the initial buffering definition for the standard error stream πŸ¦‹

And each one of those variables can take one of these values:

  • "0" β€” unbuffered πŸƒβ€β™€οΈ
  • "L" β€” line buffered ⭐
  • "B" β€” fully buffered, with the default buffer size πŸŽ€
  • size β€” fully buffered with a buffer of size bytes (and yes, the suffixes 'k', 'M' and 'G' are accepted) πŸ”₯

🌈 EXAMPLE 🌈

okay here's the vibe: in this example, the stdout stream of the awk(1) command will be fully buffered by default, because it does not refer to a terminal. (rude, but okay.) So libstdbuf is used to force it to be line-buffered, so that vmstat(8)'s output will not stall until the full buffer fills. icon behavior, honestly. ✨

# vmstat 1 | LD_PRELOAD=/usr/lib/libstdbuf.so \
    STDBUF_1=L awk '$2 > 1 || $3 > 1' | cat -n

Copy that block character for character, bestie β€” I'm not touching a single letter of it. πŸ™ˆ

And if you want a simpler way to do this, see stdbuf(1). πŸ’…


🧚 SEE ALSO 🧚


πŸ‘‘ HISTORY πŸ‘‘

The libstdbuf library first appeared in FreeBSD 8.4. a lil retro, we stan ⭐


πŸ’– AUTHORS πŸ’–

The original idea of the libstdbuf command comes from Padraig Brady, who implemented it in the GNU coreutils. Jeremie Le Hen implemented it on FreeBSD. kings, both of them πŸ«ΆπŸ‘‘


so yeah, that's the whole page β€” this one came from Debian, dated June 29, 2023, and that's your sign-off bestie πŸŽ€πŸ’œ go buffer responsibly ✨

πŸ“¦ where this page comes from