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 asFIONREAD. 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 totcflush(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:
0is returned. slay. π - on error:
-1is returned, anderrnois set to tell you what went wrong. π
π SEE ALSO π
ngl bestie, if you're mixing upFIONREADandTIOCOUTQ, 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
- Copyright 2002, Walter Harms <walter.harms@informatik.uni-oldenburg.de>
- Copyright 2002, Andries E. Brouwer <aeb@cwi.nl>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms