FIONREAD(2const)

πŸ’– FIONREAD(2const) πŸ’–

okay bestie, so this is a page from the 2const manual β€” that's the little corner of the Linux man-pages that documents standalone constants you pass to syscalls. And today's main characters? FIONREAD, TIOCINQ, TIOCOUTQ, TCFLSH, and TIOCSERGETLSR. Buffer counting and flushing. Riveting. Iconic. Let's go. ✨


🌸 LIBRARY 🌸

The standard C library, aka libc, link it with -lc. You know the drill, bestie. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <asm/termbits.h>  /* Definition of constants */
#include <sys/ioctl.h>

int ioctl(int fd, FIONREAD, int *argp);
int ioctl(int fd, TIOCINQ, int *argp);
int ioctl(int fd, TIOCOUTQ, int *argp);
int ioctl(int fd, TCFLSH, int arg);
int ioctl(int fd, TIOCSERGETLSR, int *argp);

✨ DESCRIPTION ✨

so each of these is a little request you hand to ioctl(2), and here's what each one is giving:

  • FIONREAD β€” get the number of bytes sitting in the input buffer. Just a lil headcount of what's waiting for you. πŸ’œ
  • TIOCINQ β€” literally the same thing as FIONREAD. Same energy, different name. No cap.
  • TIOCOUTQ β€” get the number of bytes in the output buffer. That's the stuff on its way out. πŸŽ€
  • TCFLSH β€” equivalent to tcflush(fd, arg).

and for what arg can actually be β€” the values are TCIFLUSH, TCOFLUSH, and TCIOFLUSH β€” go look at tcflush(3). that's where the lore lives. πŸ“š

  • TIOCSERGETLSR β€” get the line status register.

the status register has the TIOCSER_TEMT bit set when the output buffer is empty and the hardware transmitter is physically empty too. so like, truly, genuinely done transmitting. empty-empty. πŸ•³οΈ

lowkey important caveat: this does not have to be supported by all serial tty drivers. so don't come for me if your driver just doesn't. πŸ™ˆ

also tcdrain(3) does not wait and returns immediately when the TIOCSER_TEMT bit is set. no waiting around, she's already done.


⭐ RETURN VALUE ⭐

  • on success: 0 is returned. slay. πŸŽ‰
  • on error: -1 is returned, and errno is set to tell you what went wrong. πŸ’€

🌈 SEE ALSO 🌈


ngl bestie, if you're mixing up FIONREAD and TIOCOUTQ, just remember: IN is what's coming to you, OUT is what's leaving. one is your inbox, one is your sent folder. periodt. πŸ‘‘

and that's the whole page, pookie 🫢 β€” this was served fresh from Linux man-pages 6.20, dated 2026-07-02, and yeah, the source line said FIONREAD(2const) twice because the header and footer are matching outfits. obsessed. πŸ’…βœ¨

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: GPL-1.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms