LLVM OpenMP 19.0.0git
Public Member Functions | List of all members
kmp_safe_raii_file_t Class Reference

This class safely opens and closes a C-style FILE* object using RAII semantics. More...

#include "/home/buildbot/as-worker-4/publish-doxygen-docs/llvm-project/openmp/runtime/src/kmp.h"

Public Member Functions

 kmp_safe_raii_file_t ()
 
 kmp_safe_raii_file_t (const char *filename, const char *mode, const char *env_var=nullptr)
 
 ~kmp_safe_raii_file_t ()
 
void open (const char *filename, const char *mode, const char *env_var=nullptr)
 Open filename using mode.
 
int try_open (const char *filename, const char *mode)
 Instead of erroring out, return non-zero when unsuccessful fopen() for any reason.
 
void set_stdout ()
 Set the FILE* object to stdout and output there No open call should happen before this call.
 
void set_stderr ()
 Set the FILE* object to stderr and output there No open call should happen before this call.
 
 operator bool ()
 
 operator FILE * ()
 

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 4689 of file kmp.h.

Constructor & Destructor Documentation

◆ kmp_safe_raii_file_t() [1/2]

kmp_safe_raii_file_t::kmp_safe_raii_file_t ( )
inline

Definition at line 4700 of file kmp.h.

References f().

◆ kmp_safe_raii_file_t() [2/2]

kmp_safe_raii_file_t::kmp_safe_raii_file_t ( const char filename,
const char mode,
const char env_var = nullptr 
)
inline

Definition at line 4701 of file kmp.h.

References f(), mode, and open().

◆ ~kmp_safe_raii_file_t()

kmp_safe_raii_file_t::~kmp_safe_raii_file_t ( )
inline

Definition at line 4706 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 4711 of file kmp.h.

References __kmp_fatal(), __kmp_msg_null, f(), KMP_ASSERT, KMP_ERR, KMP_HNT, KMP_MSG, and mode.

Referenced by kmp_safe_raii_file_t().

◆ operator bool()

kmp_safe_raii_file_t::operator bool ( )
inline

Definition at line 4747 of file kmp.h.

References f().

◆ operator FILE *()

kmp_safe_raii_file_t::operator FILE * ( )
inline

Definition at line 4748 of file kmp.h.

References f().

◆ 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 4743 of file kmp.h.

References f(), and KMP_ASSERT.

◆ 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 4737 of file kmp.h.

References f(), and KMP_ASSERT.

◆ 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 4728 of file kmp.h.

References f(), KMP_ASSERT, and mode.


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