73 |
|
|
74 |
static VOID * |
static VOID * |
75 |
fixup_null_alloc (n) |
fixup_null_alloc (n) |
76 |
size_t n; |
size_t n; |
77 |
{ |
{ |
78 |
VOID *p; |
VOID *p; |
79 |
|
|
80 |
p = 0; |
p = 0; |
81 |
if (n == 0) |
if (n == 0) |
82 |
p = malloc ((size_t) 1); |
p = malloc ((size_t) 1); |
83 |
if (p == 0) |
if (p == 0) |
84 |
error (xmalloc_exit_failure, 0, _("Memory exhausted")); |
error (xmalloc_exit_failure, 0, _("Memory exhausted")); |
85 |
return p; |
return p; |
86 |
} |
} |
87 |
|
|
88 |
/* Allocate N bytes of memory dynamically, with error checking. */ |
/* Allocate N bytes of memory dynamically, with error checking. */ |
89 |
|
|
90 |
VOID * |
VOID * |
91 |
xmalloc (n) |
xmalloc (n) |
92 |
size_t n; |
size_t n; |
93 |
{ |
{ |
94 |
VOID *p; |
VOID *p; |
95 |
|
|
96 |
p = malloc (n); |
p = malloc (n); |
97 |
if (p == 0) |
if (p == 0) |
98 |
p = fixup_null_alloc (n); |
p = fixup_null_alloc (n); |
99 |
return p; |
return p; |
100 |
} |
} |
101 |
|
|
102 |
/* Allocate memory for N elements of S bytes, with error checking. */ |
/* Allocate memory for N elements of S bytes, with error checking. */ |
103 |
|
|
104 |
VOID * |
VOID * |
105 |
xcalloc (n, s) |
xcalloc (n, s) |
106 |
size_t n, s; |
size_t n, s; |
107 |
{ |
{ |
108 |
VOID *p; |
VOID *p; |
109 |
|
|
110 |
p = calloc (n, s); |
p = calloc (n, s); |
111 |
if (p == 0) |
if (p == 0) |
112 |
p = fixup_null_alloc (n); |
p = fixup_null_alloc (n); |
113 |
return p; |
return p; |
114 |
} |
} |
115 |
|
|
116 |
/* Change the size of an allocated block of memory P to N bytes, |
/* Change the size of an allocated block of memory P to N bytes, |
119 |
|
|
120 |
VOID * |
VOID * |
121 |
xrealloc (p, n) |
xrealloc (p, n) |
122 |
VOID *p; |
VOID *p; |
123 |
size_t n; |
size_t n; |
124 |
{ |
{ |
125 |
if (p == 0) |
if (p == 0) |
126 |
return xmalloc (n); |
return xmalloc (n); |
127 |
p = realloc (p, n); |
p = realloc (p, n); |
128 |
if (p == 0) |
if (p == 0) |
129 |
p = fixup_null_alloc (n); |
p = fixup_null_alloc (n); |
130 |
return p; |
return p; |
131 |
} |
} |
132 |
|
|
133 |
/* Make a copy of a string in a newly allocated block of memory. */ |
/* Make a copy of a string in a newly allocated block of memory. */ |
134 |
|
|
135 |
char * |
char * |
136 |
xstrdup (str) |
xstrdup (str) |
137 |
char *str; |
char *str; |
138 |
{ |
{ |
139 |
VOID *p; |
VOID *p; |
140 |
|
|
141 |
p = xmalloc (strlen (str) + 1); |
p = xmalloc (strlen (str) + 1); |
142 |
strcpy (p, str); |
strcpy (p, str); |
143 |
return p; |
return p; |
144 |
} |
} |
145 |
|
|
146 |
/**This must remain at the end of the file.********** |
/**This must remain at the end of the file.********** |
147 |
* vim600:set sw=2 ts=8: * |
* vim600:set sw=2 ts=2: * |
148 |
* vim600:set cindent cinoptions={1s,>2s,^-1s,n-1s: * |
* vim600:set cindent cinoptions={1s,>2s,^-1s,n-1s: * |
149 |
* vim600:set foldmethod=marker: * |
* vim600:set foldmethod=marker: * |
150 |
****************************************************/ |
****************************************************/ |