aboutsummaryrefslogtreecommitdiff
path: root/utility.c
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-03-21 22:32:57 +0000
committerErik Andersen <andersen@codepoet.org>2000-03-21 22:32:57 +0000
commit0d068a20676144e9fd6796cc77764c420d785394 (patch)
treeaf12b114d51e9ae7a8753baf09feb9ab8d654f26 /utility.c
parentc053e41fa0524d828bf90f47e5e3637b8facaadc (diff)
downloadbusybox-0d068a20676144e9fd6796cc77764c420d785394.tar.gz
* all mallocs now use xmalloc (and so are OOM error safe), and
the common error handling saves a few bytes. Thanks to Bob Tinsley <bob@earthrise.demon.co.uk> for the patch. -Erik
Diffstat (limited to 'utility.c')
-rw-r--r--utility.c18
1 files changed, 5 insertions, 13 deletions
diff --git a/utility.c b/utility.c
index c274bfa15..29edbf1c4 100644
--- a/utility.c
+++ b/utility.c
@@ -172,9 +172,7 @@ void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name)
i = hash_inode(statbuf->st_ino);
s = name ? strlen(name) : 0;
- bucket = malloc(sizeof(ino_dev_hashtable_bucket_t) + s);
- if (bucket == NULL)
- fatalError("Not enough memory.");
+ bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + s);
bucket->ino = statbuf->st_ino;
bucket->dev = statbuf->st_dev;
if (name)
@@ -1003,7 +1001,7 @@ extern int replace_match(char *haystack, char *needle, char *newNeedle,
if (strcmp(needle, newNeedle) == 0)
return FALSE;
- oldhayStack = (char *) malloc((unsigned) (strlen(haystack)));
+ oldhayStack = (char *) xmalloc((unsigned) (strlen(haystack)));
while (where != NULL) {
foundOne++;
strcpy(oldhayStack, haystack);
@@ -1364,22 +1362,16 @@ extern pid_t findPidByName( char* pidName)
#endif /* BB_FEATURE_USE_DEVPS_PATCH */
#endif /* BB_KILLALL || ( BB_FEATURE_LINUXRC && ( BB_HALT || BB_REBOOT || BB_POWEROFF )) */
-#if defined BB_GUNZIP \
- || defined BB_GZIP \
- || defined BB_PRINTF \
- || defined BB_TAIL
+/* this should really be farmed out to libbusybox.a */
extern void *xmalloc(size_t size)
{
void *cp = malloc(size);
- if (cp == NULL) {
- errorMsg("out of memory");
- }
+ if (cp == NULL)
+ fatalError("out of memory");
return cp;
}
-#endif /* BB_GUNZIP || BB_GZIP || BB_PRINTF || BB_TAIL */
-
#if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT)
extern int vdprintf(int d, const char *format, va_list ap)
{