Loading...
Searching...
No Matches
kmp_safe_raii_file_t Class Reference

`#include <kmp.h>`

## Public Member Functions

void | open (const char *filename, const char *mode, const char *env_var=nullptr)
int | try_open (const char *filename, const char *mode)
void | set_stdout ()
void | set_stderr ()

## Detailed Description

This class safely opens and closes a C-style FILE* object using RAII semantics. There are also methods which allow using stdout or stderr as the underlying FILE* object. With the implicit conversion operator to FILE*, an object with this type can be used in any function which takes a FILE* object e.g., fprintf(). No close method is needed at use sites.

Definition at line 4672 of file kmp.h.

## Member Function Documentation

## open()

void kmp_safe_raii_file_t::open | ( | const char * | filename,
|  | const char * | mode,
|  | const char * | env_var = `nullptr`
| ) |  |

inline

Open filename using mode. This is automatically closed in the destructor. The env_var parameter indicates the environment variable the filename came from if != nullptr.

Definition at line 4694 of file kmp.h.

## set_stderr()

void kmp_safe_raii_file_t::set_stderr | ( |  | ) |

inline

Set the FILE* object to stderr and output there No open call should happen before this call.

Definition at line 4726 of file kmp.h.

## set_stdout()

void kmp_safe_raii_file_t::set_stdout | ( |  | ) |

inline

Set the FILE* object to stdout and output there No open call should happen before this call.

Definition at line 4720 of file kmp.h.

## try_open()

int kmp_safe_raii_file_t::try_open | ( | const char * | filename,
|  | const char * | mode
| ) |  |

inline

Instead of erroring out, return non-zero when unsuccessful fopen() for any reason

Definition at line 4711 of file kmp.h.

The documentation for this class was generated from the following file:

- kmp.h