diff options
Diffstat (limited to 'packages/sundials/src/helpers.c')
-rw-r--r-- | packages/sundials/src/helpers.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/packages/sundials/src/helpers.c b/packages/sundials/src/helpers.c new file mode 100644 index 0000000..3498119 --- /dev/null +++ b/packages/sundials/src/helpers.c | |||
@@ -0,0 +1,37 @@ | |||
1 | #include <stdio.h> | ||
2 | #include "helpers.h" | ||
3 | |||
4 | /* Check function return value... | ||
5 | opt == 0 means SUNDIALS function allocates memory so check if | ||
6 | returned NULL pointer | ||
7 | opt == 1 means SUNDIALS function returns a flag so check if | ||
8 | flag >= 0 | ||
9 | opt == 2 means function allocates memory so check if returned | ||
10 | NULL pointer | ||
11 | */ | ||
12 | int check_flag(void *flagvalue, const char *funcname, int opt) | ||
13 | { | ||
14 | int *errflag; | ||
15 | |||
16 | /* Check if SUNDIALS function returned NULL pointer - no memory allocated */ | ||
17 | if (opt == 0 && flagvalue == NULL) { | ||
18 | fprintf(stderr, "\nSUNDIALS_ERROR: %s() failed - returned NULL pointer\n\n", | ||
19 | funcname); | ||
20 | return 1; } | ||
21 | |||
22 | /* Check if flag < 0 */ | ||
23 | else if (opt == 1) { | ||
24 | errflag = (int *) flagvalue; | ||
25 | if (*errflag < 0) { | ||
26 | fprintf(stderr, "\nSUNDIALS_ERROR: %s() failed with flag = %d\n\n", | ||
27 | funcname, *errflag); | ||
28 | return 1; }} | ||
29 | |||
30 | /* Check if function returned NULL pointer - no memory allocated */ | ||
31 | else if (opt == 2 && flagvalue == NULL) { | ||
32 | fprintf(stderr, "\nMEMORY_ERROR: %s() failed - returned NULL pointer\n\n", | ||
33 | funcname); | ||
34 | return 1; } | ||
35 | |||
36 | return 0; | ||
37 | } | ||