-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathlpkit.h
32 lines (26 loc) · 1.17 KB
/
lpkit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "lp_lib.h"
#include "lp_report.h"
#define MALLOC(ptr, nr, type)\
((((nr) == 0) || ((ptr = (type *) malloc((size_t)((nr) * sizeof(*ptr)))) == NULL)) ? \
report(NULL, CRITICAL, "malloc of %d bytes failed on line %d of file %s\n",\
(nr) * sizeof(*ptr), __LINE__, __FILE__), (ptr = NULL /* (void *) 0 */) : \
ptr\
)
#define CALLOC(ptr, nr, type)\
((((nr) == 0) || ((ptr = (type *) calloc((size_t)(nr), sizeof(*ptr))) == NULL)) ? \
report(NULL, CRITICAL, "calloc of %d bytes failed on line %d of file %s\n",\
(nr) * sizeof(*ptr), __LINE__, __FILE__), (ptr = NULL /* (void *) 0 */) : \
ptr\
)
#define REALLOC(ptr, nr, type)\
((((nr) == 0) || ((ptr = (type *) realloc(ptr, (size_t)((nr) * sizeof(*ptr)))) == NULL)) ? \
report(NULL, CRITICAL, "realloc of %d bytes failed on line %d of file %s\n",\
(nr) * sizeof(*ptr), __LINE__, __FILE__), (ptr = NULL /* (void *) 0 */) : \
ptr\
)
#if defined FREE
# undef FREE
#endif
#define FREE(ptr) if (ptr != NULL) {free(ptr), ptr = NULL;} else
#define MALLOCCPY(nptr, optr, nr, type)\
(MALLOC(nptr, nr, type), (nptr != NULL) ? memcpy(nptr, optr, (size_t)((nr) * sizeof(*optr))) : 0, nptr)