---
name: "auplugin_fgets"
section: "3"
platform: "linux"
package: "audit"
version: "4.2.1-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/auplugin_fgets"
---

# auplugin\_fgets(3)

buffered line reader helpers

## NAME

auplugin\_fgets, auplugin\_fgets\_more, auplugin\_fgets\_eof, auplugin\_fgets\_clear, auplugin\_setvbuf, auplugin\_setvbuf\_r - buffered line reader helpers

## SYNOPSIS

**#include \<auplugin.h\>**

**int auplugin\_fgets(char \****buf***, size\_t** *blen***, int** *fd***);**\
 **int auplugin\_fgets\_more(size\_t** *blen***);**\
 **int auplugin\_fgets\_eof(void);**\
 **void auplugin\_fgets\_clear(void);**\
 **int auplugin\_setvbuf(void \****buf***, size\_t buff\_size, enum auplugin\_mem** *how***);**\
 **int auplugin\_setvbuf\_r(auplugin\_fgets\_state\_t \****st***, void \****buf***, size\_t buff\_size, enum auplugin\_mem** *how***);**

## DESCRIPTION

**auplugin\_fgets** reads from *fd* into *buf* up to *blen* bytes or through the next newline. Text is accumulated across calls in an internal buffer so that complete lines can be returned. The string is NUL terminated.

**auplugin\_fgets\_more** checks whether the buffer holds a newline or at least *blen - 1* bytes.

**auplugin\_fgets\_eof** indicates whether end of file was reached on *fd*

**auplugin\_fgets\_clear** resets the internal buffer and EOF state, discarding any stored text. When the memory type is **MEM\_MMAP\_FILE** , the buffer is rewound to the beginning making the entire file available again.

**auplugin\_setvbuf** points the internal buffer at *buf* and sets how it will be released when **auplugin\_fgets\_destroy** is called. The *how* parameter should be one of

- **MEM\_SELF\_MANAGED - Internal buffer owned by fgets**

  - **MEM\_MALLOC - User-supplied malloc buffer; fgets frees it**

  - **MEM\_MMAP - User-supplied mmap buffer; fgets munmaps it**

  - **MEM\_MMAP\_FILE - Read-only mmap file data**

  The default is **MEM\_SELF\_MANAGED** which means its lifecycle is automatically handled. When **MEM\_MMAP\_FILE** is used, the buffer is treated as a preloaded buffer (the entire file) and no reads will be performed on the descriptor provided to **auplugin\_fgets\_r**. The reentrant form **auplugin\_setvbuf\_r** operates on an explicit state handle.

These functions maintain static state and are therefore not thread safe. For thread-safety, use the re-entrant variants.

## RETURN VALUE

**auplugin\_fgets** returns -1 on error, 0 when no data is available, or the number of characters copied otherwise.

**auplugin\_fgets\_more** and **auplugin\_fgets\_eof** return 1 for true and 0 for false.

**auplugin\_fgets\_clear** returns no value.

**auplugin\_setvbuf** returns 0 on success and 1 on failure.

## BACKGROUND

 The reason that this family of functions was created is because 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. As soon as it does, you need to read it. 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.  This family of functions allows you to correctly work only using descriptors but with the convenience of fgets.

## SEE ALSO

[**fgets**(3)](/fgets/3.md)
