mirror of
https://github.com/xzeldon/htop.git
synced 2024-12-23 22:55:46 +00:00
Combine XAlloc.[ch] into XUtils.[ch]
This commit is contained in:
parent
872e542f4e
commit
5e4b182616
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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
|
||||
|
3
Object.h
3
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;
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -17,7 +17,6 @@ in the source distribution for its full text.
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "XAlloc.h"
|
||||
#include "XUtils.h"
|
||||
|
||||
|
||||
|
42
XAlloc.c
42
XAlloc.c
@ -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;
|
||||
}
|
22
XAlloc.h
22
XAlloc.h
@ -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
|
31
XUtils.c
31
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);
|
||||
|
11
XUtils.h
11
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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user