### 5.19 `fpurge`—discard pending file I/O ¶

Synopsis

    #include <stdio.h>
    int fpurge(FILE *fp);

    int _fpurge_r(struct _reent *reent, FILE *fp);

    #include <stdio.h>
    #include <stdio_ext.h>
    void  __fpurge(FILE *fp);

Description
Use `fpurge` to clear all buffers of the given stream. For output streams, this discards data not yet written to disk. For input streams, this discards any data from `ungetc` and any data retrieved from disk but not yet read via `getc`. This is more severe than `fflush`, and generally is only needed when manually altering the underlying file descriptor of a stream.

`__fpurge` behaves exactly like `fpurge` but does not return a value.

The alternate function `_fpurge_r` is a reentrant version, where the extra argument reent is a pointer to a reentrancy structure, and fp must not be NULL.

Returns
`fpurge` returns `0` unless fp is not valid, in which case it returns `EOF` and sets `errno`.

Portability
These functions are not portable to any standard.

No supporting OS subroutines are required.