aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcathook <cat.hook31894@gmail.com>2013-11-26 00:02:50 +0800
committercathook <cat.hook31894@gmail.com>2013-11-26 02:41:11 +0800
commitc88ab16511df6eef6f7017a39e1a48deed6bd1f3 (patch)
tree1d3310096973c15661878bdcbc60f0689cd58072
parent5c6353aac348cfe3b9ac56110dbdf7a56afc1fbd (diff)
downloadctl-c88ab16511df6eef6f7017a39e1a48deed6bd1f3.tar.gz
ctl-c88ab16511df6eef6f7017a39e1a48deed6bd1f3.tar.zst
ctl-c88ab16511df6eef6f7017a39e1a48deed6bd1f3.zip
add ctl_free function
-rw-r--r--include/utility.h8
-rw-r--r--src/utility.c6
2 files changed, 11 insertions, 3 deletions
diff --git a/include/utility.h b/include/utility.h
index 2e4330d..f51a646 100644
--- a/include/utility.h
+++ b/include/utility.h
@@ -33,6 +33,7 @@
/* Functions: */
/* ctl_malloc like malloc(), but will exit on error */
/* ctl_realloc like realloc(), but will exit on erro */
+/* ctl_free like free(), but will return NULL */
/* ctl_die print some message and exit() */
/* ctl_swap swap two elements with given type */
/* */
@@ -43,11 +44,11 @@ typedef enum{
} ErrorType;
// int
-typedef *int pint;
+typedef int* pint;
typedef unsigned int uint;
typedef uint* puint;
typedef const int cint;
-typedef *cint pcint;
+typedef cint* pcint;
typedef const uint cuint;
typedef cuint* pcuint;
#define Int(X) (( int)(X))
@@ -98,7 +99,8 @@ typedef pcuchar* ppcuchar;
#define ppcuChar(X) ((ppcuchar)(X))
pvoid ctl_malloc (size_t size);
-pvoid ctl_realloc(pvoid *ptr, size_t size);
+pvoid ctl_realloc(pvoid ptr, size_t size);
+pvoid ctl_free (pvoid ptr);
void ctl_die (ErrorType e);
#define ctl_swap(X,Y,Z) do{X zzzztmp=(Y);(Y)=(Z);(Z)=zzzztmp;}while(0)
diff --git a/src/utility.c b/src/utility.c
index bcc2500..7287908 100644
--- a/src/utility.c
+++ b/src/utility.c
@@ -22,6 +22,12 @@ pvoid ctl_realloc(pvoid ptr, size_t size){
return ptr;
}
+/*********** like free(), but will return NULL ************/
+pvoid ctl_free(pvoid ptr){
+ free(ptr);
+ return NULL;
+}
+
/********* print some message on STDERR and exit() ********/
void ctl_die(ErrorType e){
fprintf(stderr, "exit(%d): ", (int)e);