c-template
returns.c
Go to the documentation of this file.
1
#include <stdlib.h>
2
#include "../../include/utils/errors.h"
3
#include "../../include/utils/returns.h"
4
5
cg_return
*
new_cg_return
(
void
*value,
cg_error
*err) {
6
cg_return
*ret = calloc(
sizeof
(
cg_return
),
sizeof
(value) +
sizeof
(err));
7
if
(ret == NULL) {
8
printf(
"failed to calloc cg_return\n"
);
9
return
NULL;
10
}
11
if
(err != NULL) {
12
ret->
err
= err;
13
}
else
{
14
ret->
err
= NULL;
15
}
16
if
(value != NULL) {
17
ret->
value
= value;
18
}
else
{
19
ret->
value
= NULL;
20
}
21
return
ret;
22
}
23
24
void
free_cg_return
(
cg_return
*ret) {
25
// TODO(bonedaddy): determine how we can determine if ret->value needs to be freed
26
if
(ret->
err
!= NULL) {
27
free_cg_error
(ret->
err
);
28
}
29
free(ret);
30
}
cg_return::value
void * value
Definition:
returns.h:16
cg_return::err
cg_error * err
Definition:
returns.h:19
new_cg_return
cg_return * new_cg_return(void *value, cg_error *err)
creates a new cg_return struct
Definition:
returns.c:5
free_cg_error
void free_cg_error(cg_error *error)
frees up resources associated with error
Definition:
errors.c:39
cg_return
allows returning both a value and error message from a function call useful as it makes it easier to ...
Definition:
returns.h:14
cg_error
Definition:
errors.h:14
free_cg_return
void free_cg_return(cg_return *ret)
frees up resources associated with an instance of cg_return
Definition:
returns.c:24
src
utils
returns.c
Generated by
1.8.17