From 5e4b1826168b74d8b5e71227ded12980efd5a243 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Thu, 15 Oct 2020 00:56:22 +0200 Subject: [PATCH] Combine XAlloc.[ch] into XUtils.[ch] --- FunctionBar.c | 1 - Hashtable.c | 2 +- Makefile.am | 2 -- Object.h | 3 ++- RichString.c | 3 ++- UsersTable.c | 1 - XAlloc.c | 42 ------------------------------------------ XAlloc.h | 22 ---------------------- XUtils.c | 31 ++++++++++++++++++++++++++++++- XUtils.h | 11 +++++++++++ 10 files changed, 46 insertions(+), 72 deletions(-) delete mode 100644 XAlloc.c delete mode 100644 XAlloc.h diff --git a/FunctionBar.c b/FunctionBar.c index 4e9d30cd..50bae0b1 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -8,7 +8,6 @@ in the source distribution for its full text. #include "FunctionBar.h" #include "CRT.h" #include "RichString.h" -#include "XAlloc.h" #include "XUtils.h" #include diff --git a/Hashtable.c b/Hashtable.c index 383b34a8..a086227c 100644 --- a/Hashtable.c +++ b/Hashtable.c @@ -6,7 +6,7 @@ in the source distribution for its full text. */ #include "Hashtable.h" -#include "XAlloc.h" +#include "XUtils.h" #include #include diff --git a/Makefile.am b/Makefile.am index 0c3b68c0..fd02bb3e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -62,7 +62,6 @@ myhtopsources = \ UptimeMeter.c \ UsersTable.c \ Vector.c \ - XAlloc.c \ XUtils.c myhtopheaders = \ @@ -114,7 +113,6 @@ myhtopheaders = \ UptimeMeter.h \ UsersTable.h \ Vector.h \ - XAlloc.h \ XUtils.h # Linux diff --git a/Object.h b/Object.h index f601ddf0..6c31fa34 100644 --- a/Object.h +++ b/Object.h @@ -9,8 +9,9 @@ in the source distribution for its full text. */ #include "RichString.h" -#include "XAlloc.h" #include "Macros.h" +#include "XUtils.h" + typedef struct Object_ Object; diff --git a/RichString.c b/RichString.c index 8019135e..3cb19ae4 100644 --- a/RichString.c +++ b/RichString.c @@ -6,12 +6,13 @@ in the source distribution for its full text. */ #include "RichString.h" -#include "XAlloc.h" #include "Macros.h" +#include "XUtils.h" #include #include + #define charBytes(n) (sizeof(CharType) * (n)) static void RichString_extendLen(RichString* this, int len) { diff --git a/UsersTable.c b/UsersTable.c index e37c9038..41e52d3f 100644 --- a/UsersTable.c +++ b/UsersTable.c @@ -17,7 +17,6 @@ in the source distribution for its full text. #include #include -#include "XAlloc.h" #include "XUtils.h" diff --git a/XAlloc.c b/XAlloc.c deleted file mode 100644 index 815cf47f..00000000 --- a/XAlloc.c +++ /dev/null @@ -1,42 +0,0 @@ - -#include "XAlloc.h" -#include "RichString.h" - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include -#include -#include - - -void fail() { - curs_set(1); - endwin(); - abort(); -} - -void* xMalloc(size_t size) { - void* data = malloc(size); - if (!data && size > 0) { - fail(); - } - return data; -} - -void* xCalloc(size_t nmemb, size_t size) { - void* data = calloc(nmemb, size); - if (!data && nmemb > 0 && size > 0) { - fail(); - } - return data; -} - -void* xRealloc(void* ptr, size_t size) { - void* data = realloc(ptr, size); - if (!data && size > 0) { - fail(); - } - return data; -} diff --git a/XAlloc.h b/XAlloc.h deleted file mode 100644 index 98a422fc..00000000 --- a/XAlloc.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef HEADER_XAlloc -#define HEADER_XAlloc - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include "Macros.h" - -#include -#include -#include - -void fail(void) ATTR_NORETURN; - -void* xMalloc(size_t size); - -void* xCalloc(size_t nmemb, size_t size); - -void* xRealloc(void* ptr, size_t size); - -#endif diff --git a/XUtils.c b/XUtils.c index 9228c5e8..f654b4bc 100644 --- a/XUtils.c +++ b/XUtils.c @@ -14,9 +14,38 @@ in the source distribution for its full text. #include #include -#include "XAlloc.h" +#include "CRT.h" +void fail() { + CRT_done(); + abort(); +} + +void* xMalloc(size_t size) { + void* data = malloc(size); + if (!data && size > 0) { + fail(); + } + return data; +} + +void* xCalloc(size_t nmemb, size_t size) { + void* data = calloc(nmemb, size); + if (!data && nmemb > 0 && size > 0) { + fail(); + } + return data; +} + +void* xRealloc(void* ptr, size_t size) { + void* data = realloc(ptr, size); + if (!data && size > 0) { + fail(); + } + return data; +} + char* String_cat(const char* s1, const char* s2) { int l1 = strlen(s1); int l2 = strlen(s2); diff --git a/XUtils.h b/XUtils.h index 4880d1a1..742b8e9e 100644 --- a/XUtils.h +++ b/XUtils.h @@ -7,11 +7,22 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include +#include #include +#include #include "Macros.h" +void fail(void) ATTR_NORETURN; + +void* xMalloc(size_t size); + +void* xCalloc(size_t nmemb, size_t size); + +void* xRealloc(void* ptr, size_t size); + #define String_startsWith(s, match) (strncmp((s),(match),strlen(match)) == 0) #define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL)