GRU - Generic Reusable Utilities
Loading...
Searching...
No Matches
Functions
gru_ioutils.c File Reference
#include "gru_ioutils.h"
#include "common/gru_alloc.h"

Functions

bool gru_io_remap (const char *dir, const char *name, FILE *fd, gru_status_t *status)
 IO utilities. More...
 
FILE * gru_io_open_file_path (const char *path, gru_status_t *status)
 Tries to safely open a file (ie.: creating directories and stuff). More...
 
FILE * gru_io_open_file (const char *dir, const char *name, gru_status_t *status)
 Tries to safely open a file (ie.: creating directories and stuff). More...
 
FILE * gru_io_open_file_read (const char *dir, const char *name, gru_status_t *status)
 Tries to safely open a file (ie.: creating directories and stuff) More...
 
FILE * gru_io_open_file_read_path (const char *path, gru_status_t *status)
 Tries to safely open a file (ie.: creating directories and stuff) More...
 
FILE * gru_io_open_unique_file (const char *dir, const char *name, gru_status_t *status)
 Tries to safely open a file (ie.: creating directories and stuff) More...
 
size_t gru_io_read_text_into (char **dest, FILE *file, gru_status_t *status)
 Reads the file pointed by file into the destination buffer. More...
 

Function Documentation

◆ gru_io_open_file()

FILE * gru_io_open_file ( const char *  dir,
const char *  name,
gru_status_t status 
)

Tries to safely open a file (ie.: creating directories and stuff).

Truncates the file

Parameters
dirdirectory of the file
namename of the file
statusstatus structure containing error code/description in case of failure
Returns
a FILE descriptor for the opened file or NULL otherwise (in this case, check status)

◆ gru_io_open_file_path()

FILE * gru_io_open_file_path ( const char *  path,
gru_status_t status 
)

Tries to safely open a file (ie.: creating directories and stuff).

Truncates the file

Parameters
pathpath to the file
statusstatus structure containing error code/description in case of failure
Returns
a FILE descriptor for the opened file or NULL otherwise (in this case, check status)

◆ gru_io_open_file_read()

FILE * gru_io_open_file_read ( const char *  dir,
const char *  name,
gru_status_t status 
)

Tries to safely open a file (ie.: creating directories and stuff)

Parameters
dirdirectory of the file
namename of the file
statusstatus structure containing error code/description in case of failure
Returns
a FILE descriptor for the opened file or NULL otherwise (in this case, check status)

◆ gru_io_open_file_read_path()

FILE * gru_io_open_file_read_path ( const char *  path,
gru_status_t status 
)

Tries to safely open a file (ie.: creating directories and stuff)

Parameters
pathpath to the file
statusstatus structure containing error code/description in case of failure
Returns
a FILE descriptor for the opened file or NULL otherwise (in this case, check status)

◆ gru_io_open_unique_file()

FILE * gru_io_open_unique_file ( const char *  dir,
const char *  name,
gru_status_t status 
)

Tries to safely open a file (ie.: creating directories and stuff)

Parameters
dirdirectory of the file
namename of the file
statusstatus structure containing error code/description in case of failure
Returns
a FILE descriptor for the opened file or NULL otherwise (in this case, check status)

◆ gru_io_read_text_into()

size_t gru_io_read_text_into ( char **  dest,
FILE *  file,
gru_status_t status 
)

Reads the file pointed by file into the destination buffer.

The memory for the allocation buffer is allocated as needed and must be free'd after use

Parameters
destthe destination buffer
filethe file to read
statusstatus structure containing error code/description in case of failure
Returns
the amount of bytes read of 0 in case of error

◆ gru_io_remap()

bool gru_io_remap ( const char *  dir,
const char *  name,
FILE *  fd,
gru_status_t status 
)

IO utilities.

Lot's of nonsense here. Most will be fixed/rewritten in the future. Remaps IO from one file descriptor to a file pointed by dir/name

Parameters
dirdirectory of the file
namename of the file
fdfile descriptor to remap
statusstatus structure containing error code/description in case of failure
Returns
true if remapped or false otherwise (in this case, check status)