EVSL  1.1.0
EigenValues Slicing Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
cs_malloc.c
Go to the documentation of this file.
1 #include "cs.h"
2 #ifdef MATLAB_MEX_FILE
3 #define malloc mxMalloc
4 #define free mxFree
5 #define realloc mxRealloc
6 #define calloc mxCalloc
7 #endif
8 
9 /* wrapper for malloc */
10 void *cs_malloc (CS_INT n, size_t size)
11 {
12  return (malloc (CS_MAX (n,1) * size)) ;
13 }
14 
15 /* wrapper for calloc */
16 void *cs_calloc (CS_INT n, size_t size)
17 {
18  return (calloc (CS_MAX (n,1), size)) ;
19 }
20 
21 /* wrapper for free */
22 void *cs_free (void *p)
23 {
24  if (p) free (p) ; /* free p if it is not already NULL */
25  return (NULL) ; /* return NULL to simplify the use of cs_free */
26 }
27 
28 /* wrapper for realloc */
29 void *cs_realloc (void *p, CS_INT n, size_t size, CS_INT *ok)
30 {
31  void *pnew ;
32  pnew = realloc (p, CS_MAX (n,1) * size) ; /* realloc the block */
33  *ok = (pnew != NULL) ; /* realloc fails if pnew is NULL */
34  return ((*ok) ? pnew : p) ; /* return original p if failure */
35 }
void * cs_free(void *p)
Definition: cs_malloc.c:22
#define CS_MAX(a, b)
Definition: cs.h:653
void * cs_calloc(CS_INT n, size_t size)
Definition: cs_malloc.c:16
void * cs_realloc(void *p, CS_INT n, size_t size, CS_INT *ok)
Definition: cs_malloc.c:29
#define CS_INT
Definition: cs.h:627
void * cs_malloc(CS_INT n, size_t size)
Definition: cs_malloc.c:10