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 00:02:50 +0800
commitc165b1464abc76e747ea0b6e3f2a7cd27aac0a5d (patch)
tree241bfe3f4f0bb1f79e96368c62d0155224804464
parent24ec80854b0145eac5f6401ca34ee82121468064 (diff)
downloadctl-c165b1464abc76e747ea0b6e3f2a7cd27aac0a5d.tar.gz
ctl-c165b1464abc76e747ea0b6e3f2a7cd27aac0a5d.tar.zst
ctl-c165b1464abc76e747ea0b6e3f2a7cd27aac0a5d.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);