explain_tcflush_or_die(3)

πŸ“¦
version 1.4.D001 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute

πŸ’– explain_tcflush_or_die β€” discard terminal data and report errors πŸ’–

okay bestie, so you know how tcflush(3) just... does its thing and if it breaks you're left standing there like πŸ‘οΈπŸ‘„πŸ‘οΈ with zero clue why? yeah. this is the glow-up. it's from the libexplain library, and it's literally here to hold your hand and tell you what went wrong. no cap.


✨ SYNOPSIS ✨

#include <libexplain/tcflush.h>
void explain_tcflush_or_die(int fildes, int selector);
int explain_tcflush_on_error(int fildes, int selector);

like, that's it. two little functions. two little icons. 🫢


🌸 DESCRIPTION 🌸

okay so the way this works is lowkey iconic:

  • explain_tcflush_or_die β€” this one calls the tcflush(3) system call for you. and if it fails? it prints a whole explanation to stderr (pulled straight from explain_tcflush(3), the drama queen that knows everything) and then the process just ends, by calling exit(EXIT_FAILURE). it's giving main character exit. πŸ’€
  • explain_tcflush_on_error β€” same energy, calls tcflush(3), prints that same explanation to stderr from explain_tcflush(3) on failure... but it's chiller about it and still returns to the caller. no dramatic exit, just receipts. πŸ™ˆ

the args, bestie

  • fildes β€” the fildes, exactly as to be passed to the tcflush(3) system call. don't get cute with it, pass it exactly.
  • selector β€” the selector, exactly as to be passed to the tcflush(3) system call. same rule, periodt.

⭐ RETURN VALUE ⭐

  • explain_tcflush_or_die only returns on success β€” go peek at tcflush(3) if you want the deets. on failure it prints that explanation and exits. it does not return. not even a little. 🚫
  • explain_tcflush_on_error always returns the value returned by the wrapped tcflush(3) system call. every single time. reliable queen. πŸ‘‘

πŸ¦‹ EXAMPLE πŸ¦‹

the explain_tcflush_or_die function is intended to be used in a fashion similar to this lil snippet:

explain_tcflush_or_die(fildes, selector);

that's the whole vibe check. copy, paste, slay. ✨


πŸ’œ SEE ALSO πŸ’œ

iykyk, these are the besties that come as a set. πŸŽ€


  • libexplain version 1.4
  • Copyright (C) 2009 Peter Miller

and that's the whole page, babe πŸ’… this was libexplain version 1.4, Copyright (C) 2009 Peter Miller β€” go forth, flush those terminal buffers, and let the library do the explaining for you. mwah. πŸŒˆπŸ¦‹πŸ’–

πŸ“¦ where this page comes from