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
Data Structures
sb-error.h File Reference

Error reporting infrastructure. More...

`#include <stdarg.h>`
`#include <stdlib.h>`

Go to the source code of this file.

## Data Structures
struct | sb_error_t
enum | { SB_ERROR_FILE_OPEN = -1, SB_ERROR_FILE_READ = -2, SB_ERROR_FILE_WRITE = -3, SB_ERROR_DIR_CREATE = -4, SB_ERROR_CONFIGPARSER = -10 }
sb_error_t * | sb_error_new (int code, const char *msg)
sb_error_t * | sb_error_new_printf (int code, const char *format,...)
sb_error_t * | sb_error_new_printf_parser (int code, const char *src, size_t src_len, size_t current, const char *format,...)
void | sb_error_free (sb_error_t *err)

## Detailed Description

Error reporting infrastructure.

This implementation is meant to be simple and easy to use, without global variables, etc. If user needs something more advanced, like support to repeated error codes, splitted error types for each type of error, etc., such solution should be implemented in the application itself.

## Enumeration Type Documentation

anonymous enum

Internal error codes.

This is an enum with all error codes used by squareball library itself. They start from 262144 (0x1000000) to avoid conflicts with application error codes.

## Function Documentation

void sb_error_free | ( | sb_error_t * | err | ) |

Function that frees memory allocated for an error object.

Parameters

  err | An error object.

Examples:
  hello_configparser.c, hello_dir_create.c, hello_file_read.c, and hello_file_write.c.

sb_error_t* sb_error_new | ( | int | code,
|  | const char * | msg
| ) |  |

Function that creates a new error object.

Parameters

  code | Error code.
  msg | Human-readable error message.

Returns
  An error object.

sb_error_t* sb_error_new_printf | ( | int | code,
|  | const char * | format,
|  |  | ...
| ) |  |

Function that creates a new error object, with printf(3)-like message formatting.

Parameters

  code | Error code.
  format | Format for human-readable error message.
  ... | One or more printf(3)-like parameters.

Returns
  An error object.

sb_error_t* sb_error_new_printf_parser | ( | int | code,
|  | const char * | src,
|  | size_t | src_len,
|  | size_t | current,
|  | const char * | format,
|  |  | ...
| ) |  |

Function that creates a new error object, with printf(3)-like message formatting and parser current position details.

Parameters

  code | Error code.
  src | String with source that was being parsed.
  src_len | Source string size.
  current | Current parser position, stating from `0`.
  format | Format for human-readable error message.
  ... | One or more printf(3)-like parameters.

Returns
  An error object.