AUDIT_FGETS(3)
π AUDIT_FGETS π
okay bestie, welcome to AUDIT_FGETS(3) β yes it's a real Linux Audit API page and yes it's lowkey iconic. these are the buffered line reader helpers, and honestly? they're giving "fgets but make it descriptors." π¦
β¨ NAME β¨
audit_fgets, audit_fgets_more, audit_fgets_eof, audit_fgets_clear β buffered line reader helpers π
β¨ SYNOPSIS β¨
#include <libaudit.h>
int audit_fgets(char *buf, size_t blen, int fd);
int audit_fgets_more(size_t blen);
int audit_fgets_eof(void);
void audit_fgets_clear(void);
periodt. four little functions, one big vibe. π
β¨ DESCRIPTION β¨
so here's the tea. πΈ
audit_fgetsreads fromfdintobuf, up toblenbytes or all the way through the next newline β whichever comes first. the text gets accumulated across calls in an internal buffer, so complete lines can be returned to you like little gifts. π and yes, the string is NUL terminated, we're not animals.audit_fgets_morechecks whether the buffer holds a newline, or at leastblen - 1bytes. basically it's the "do we have enough yet??" check. πaudit_fgets_eoftells you whether end of file was reached onfd. it's the "are we done here" indicator, no cap.audit_fgets_clearresets the internal buffer and the EOF state, discarding any stored text. it's giving factory reset but make it cute. β¨
π¨ important vibe check: these functions maintain static state and are therefore not thread safe. so like, don't be messy with them across threads, bestie. π
β¨ RETURN VALUE β¨
audit_fgetsreturns-1on error,0when no data is available, or otherwise the number of characters copied. three moods fr fr.audit_fgets_moreandaudit_fgets_eofreturn1for true and0for false. simple, clean, slay.audit_fgets_clearreturns no value. it just does the thing. π
β¨ BACKGROUND β¨
okay so WHY does this whole family of functions even exist?? π§
the reason is that in auditd plugins, the event stream is stdin, which is descriptor 0. a typical pattern is to call select, poll, or epoll to wait for a record to arrive β and as soon as it does, you need to read it. β‘
but if you use fgets, you will wind up with big problems, because you cannot mix low level descriptors with high level constructs like struct FILE. it's giving oil and water. π
this family of functions lets you correctly work only using descriptors, but with the convenience of fgets. best of both worlds, main character energy. π
β¨ SEE ALSO β¨
fgets(3)β the OG. the blueprint. the moment. π
and that's the whole page, bestie!! written by the lovely folks at Red Hat, dated May 2025, and filed under AUDIT_FGETS(3) in section 3 of your friendly neighborhood manual. π«Άβ¨ mwah, go read some lines. π
π¦ where this page comes from
- ubuntu questing: libaudit-dev 1:4.0.5-1build1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms