29 |
{ |
{ |
30 |
void *p; |
void *p; |
31 |
|
|
32 |
p = (void *)malloc(n); |
p = malloc(n); |
33 |
if (p == 0) { |
if (p == NULL) { |
34 |
anubis_error(HARD, |
anubis_error(HARD, |
35 |
_("malloc() failed. Cannot allocate enough memory.")); |
_("malloc() failed. Cannot allocate enough memory.")); |
36 |
quit(EXIT_FAILURE); /* force exit */ |
quit(EXIT_FAILURE); /* force exit */ |
37 |
} |
} |
38 |
else |
memset(p, 0, n); |
|
memset(p, 0, n); |
|
39 |
return p; |
return p; |
40 |
} |
} |
41 |
|
|
42 |
void * |
void * |
43 |
xrealloc(void *p, int n) |
xrealloc(void *p, int n) |
44 |
{ |
{ |
45 |
if (p == 0) |
if (p == NULL) |
46 |
return xmalloc(n); |
return xmalloc(n); |
47 |
|
|
48 |
p = (void *)realloc(p, n); |
p = realloc(p, n); |
49 |
if (p == 0) { |
if (p == NULL) { |
50 |
anubis_error(HARD, |
anubis_error(HARD, |
51 |
_("realloc() failed. Cannot reallocate enough memory.")); |
_("realloc() failed. Cannot reallocate enough memory.")); |
52 |
quit(EXIT_FAILURE); /* force exit */ |
quit(EXIT_FAILURE); /* force exit */ |
57 |
char * |
char * |
58 |
allocbuf(char *s, int maxsize) |
allocbuf(char *s, int maxsize) |
59 |
{ |
{ |
60 |
char *p = 0; |
char *p = NULL; |
61 |
int len; |
int len; |
62 |
|
|
63 |
if (s == 0) |
if (s == NULL) |
64 |
return 0; |
return NULL; |
65 |
|
|
66 |
len = strlen(s); |
len = strlen(s); |
67 |
if (maxsize != 0) { |
if (maxsize != 0) { |
76 |
return p; |
return p; |
77 |
} |
} |
78 |
else |
else |
79 |
return 0; |
return NULL; |
80 |
} |
} |
81 |
|
|
82 |
#ifndef HAVE_STRDUP |
#ifndef HAVE_STRDUP |
83 |
char * |
char * |
84 |
strdup(const char *s) |
strdup(const char *s) |
85 |
{ |
{ |
86 |
char *p = 0; |
char *p = NULL; |
87 |
int len; |
int len; |
88 |
|
|
89 |
if (s == 0) |
if (s == NULL) |
90 |
return 0; |
return NULL; |
91 |
|
|
92 |
len = strlen(s); |
len = strlen(s); |
93 |
p = (char *)xmalloc(len + 1); |
p = (char *)xmalloc(len + 1); |