c-template
errors.h
Go to the documentation of this file.
1
/*! @file errors.h
2
* @brief golang like error handling
3
*/
4
5
#pragma once
6
7
#include <string.h>
8
#include <stdlib.h>
9
#include <stdio.h>
10
#include <stdatomic.h>
11
12
/*! @struct wraps strings into a struct with error handling functionality
13
*/
14
typedef
struct
{
15
char
*
message
;
16
}
cg_error
;
17
18
/*! @brief returns a cg_error struct containing message
19
*/
20
cg_error
*
new_cg_error
(
char
*message);
21
/*! @brief creates a new variable and moves memory of message into that variable returning it
22
* this appears to be needed as if we dont do this `realloc` will complain about an invalid pointer
23
*/
24
char
*
cg_error_string
(
char
*message);
25
/*! @brief appends message to the end of error->message
26
* uses realloc to maximize memory efficiency
27
*/
28
int
wrap_cg_error
(
cg_error
*error,
char
*message);
29
/*! @brief frees up resources associated with error
30
*/
31
void
free_cg_error
(
cg_error
*error);
new_cg_error
cg_error * new_cg_error(char *message)
returns a cg_error struct containing message
Definition:
errors.c:7
wrap_cg_error
int wrap_cg_error(cg_error *error, char *message)
appends message to the end of error->message uses realloc to maximize memory efficiency
Definition:
errors.c:28
cg_error::message
char * message
Definition:
errors.h:15
cg_error_string
char * cg_error_string(char *message)
creates a new variable and moves memory of message into that variable returning it this appears to be...
Definition:
errors.c:17
free_cg_error
void free_cg_error(cg_error *error)
frees up resources associated with error
Definition:
errors.c:39
cg_error
Definition:
errors.h:14
include
utils
errors.h
Generated by
1.8.17