c-template
errors.h File Reference

golang like error handling More...

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdatomic.h>
Include dependency graph for errors.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  cg_error
 

Functions

cg_errornew_cg_error (char *message)
 returns a cg_error struct containing message More...
 
char * cg_error_string (char *message)
 creates a new variable and moves memory of message into that variable returning it this appears to be needed as if we dont do this realloc will complain about an invalid pointer More...
 
int wrap_cg_error (cg_error *error, char *message)
 appends message to the end of error->message uses realloc to maximize memory efficiency More...
 
void free_cg_error (cg_error *error)
 frees up resources associated with error More...
 

Detailed Description

golang like error handling

provides a C equivlent of golang function returns it enables returning two values from function call, one being an error (if any) and one being data if any

Definition in file errors.h.

Function Documentation

◆ 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 needed as if we dont do this realloc will complain about an invalid pointer

Definition at line 17 of file errors.c.

Here is the caller graph for this function:

◆ free_cg_error()

void free_cg_error ( cg_error error)

frees up resources associated with error

Definition at line 39 of file errors.c.

Here is the caller graph for this function:

◆ new_cg_error()

cg_error* new_cg_error ( char *  message)

returns a cg_error struct containing message

Definition at line 7 of file errors.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 at line 28 of file errors.c.

Here is the caller graph for this function: