Combine XAlloc.[ch] into XUtils.[ch]

This commit is contained in:
Benny Baumann 2020-10-15 00:56:22 +02:00
parent 872e542f4e
commit 5e4b182616
10 changed files with 46 additions and 72 deletions

View File

@ -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>

View File

@ -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>

View File

@ -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

View File

@ -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;

View File

@ -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) {

View File

@ -17,7 +17,6 @@ in the source distribution for its full text.
#include <stdlib.h>
#include <assert.h>
#include "XAlloc.h"
#include "XUtils.h"

View File

@ -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;
}

View File

@ -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

View File

@ -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);

View File

@ -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)