summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenny Baumann <BenBE@geshi.org>2020-10-15 00:56:22 +0200
committerBenny Baumann <BenBE@geshi.org>2020-10-17 20:54:14 +0200
commit5e4b1826168b74d8b5e71227ded12980efd5a243 (patch)
treed1b5ce276eb0ba146abaabb8ae1ddda793d230c0
parent872e542f4eca52ce2198ba3fc30a51bc5d672dae (diff)
Combine XAlloc.[ch] into XUtils.[ch]
-rw-r--r--FunctionBar.c1
-rw-r--r--Hashtable.c2
-rw-r--r--Makefile.am2
-rw-r--r--Object.h3
-rw-r--r--RichString.c3
-rw-r--r--UsersTable.c1
-rw-r--r--XAlloc.c42
-rw-r--r--XAlloc.h22
-rw-r--r--XUtils.c31
-rw-r--r--XUtils.h11
10 files changed, 46 insertions, 72 deletions
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 <assert.h>
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 <stdlib.h>
#include <assert.h>
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 <stdlib.h>
#include <string.h>
+
#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 <stdlib.h>
#include <assert.h>
-#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 <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-
-
-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 <assert.h>
-#include <err.h>
-#include <stdlib.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);
-
-#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 <string.h>
#include <strings.h>
-#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 <assert.h>
+#include <err.h>
#include <stdio.h>
+#include <stdlib.h>
#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)

© 2014-2024 Faster IT GmbH | imprint | privacy policy