squareball/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.

This function can generate errors with the following codes:

  • SB_ERROR_FILE_OPEN
  • SB_ERROR_FILE_READ
Parameters:
path File path.
len Location to store length of file, in bytes, or NULL.
err Return 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.

This function can generate errors with the following codes:

  • SB_ERROR_FILE_OPEN
  • SB_ERROR_FILE_READ
Parameters:
path File path.
len Location to store length of file, in bytes, or NULL.
err Return 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.

This function can generate errors with the following codes:

  • SB_ERROR_FILE_OPEN
  • SB_ERROR_FILE_WRITE
Parameters:
path File path.
contents Content.
len Content length.
err Return 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.

This function can generate errors with the following codes:

  • SB_ERROR_DIR_CREATE
Parameters:
path Directory path.
err Return location for a sb_error_t, or NULL.
Examples:
hello_dir_create.c.

Generated on 7 Apr 2018 for squareball by  doxygen 1.6.1