squareball 0.2.0.28-7bb8 A general-purpose library for C99

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

All Data Structures Files Functions Variables Typedefs
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)
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_configparser.c, and hello_file_read.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.