squareball  0.2.0.51-89d5
A general-purpose library for C99
sb-file.h File Reference

File utilities. More...

Go to the source code of this file.

Functions

char * sb_file_get_contents (const char *path, size_t *len, sb_error_t **err)
 
char * sb_file_get_contents_utf8 (const char *path, size_t *len, sb_error_t **err)
 
void sb_file_put_contents (const char *path, const char *contents, size_t len, sb_error_t **err)
 
void sb_mkdir_recursive (const char *path, sb_error_t **err)
 

Detailed Description

File utilities.

Function Documentation

char* sb_file_get_contents ( const char *  path,
size_t *  len,
sb_error_t **  err 
)

Function that reads the content of a file.

Parameters
pathFile path.
lenLocation to store length of file, in bytes, or NULL.
errReturn location for a sb_error_t, or NULL.
Returns
A string with the content of the file, or NULL if some error happened.
Examples:
hello_file_read.c.
char* sb_file_get_contents_utf8 ( const char *  path,
size_t *  len,
sb_error_t **  err 
)

Function that reads the content of a file, checking if it is encoded in UTF-8 and removing UTF-8 BOM, if needed.

Parameters
pathFile path.
lenLocation to store length of file, in bytes, or NULL.
errReturn location for a sb_error_t, or NULL.
Returns
A string with the content of the file, or NULL if some error happened.
Examples:
hello_configparser.c.
void sb_file_put_contents ( const char *  path,
const char *  contents,
size_t  len,
sb_error_t **  err 
)

Function that writes content to a file.

Parameters
pathFile path.
contentsContent.
lenContent length.
errReturn location for a sb_error_t, or NULL.
Examples:
hello_file_write.c.
void sb_mkdir_recursive ( const char *  path,
sb_error_t **  err 
)

Function that creates directories recursively. It respects umask when creating directories.

Parameters
pathDirectory path.
errReturn location for a sb_error_t, or NULL.
Examples:
hello_dir_create.c.