diff options
author | Jari Aalto <jari.aalto@cante.net> | 1999-02-19 17:11:39 +0000 |
---|---|---|
committer | Jari Aalto <jari.aalto@cante.net> | 2009-09-12 16:46:52 +0000 |
commit | b72432fdcc59300c6fe7c9d6c8a31ad3447933f5 (patch) | |
tree | b9899162338c2ff3fd83a8aef8831cb119e85cd7 /xmalloc.c | |
parent | bc4cd23ce958feda898c618215f94d8a4e8f4ffa (diff) | |
download | bash-b72432fdcc59300c6fe7c9d6c8a31ad3447933f5.tar.gz |
Imported from ../bash-2.03.tar.gz.
Diffstat (limited to 'xmalloc.c')
-rw-r--r-- | xmalloc.c | 37 |
1 files changed, 24 insertions, 13 deletions
@@ -46,7 +46,7 @@ # endif /* !__STDC__ */ #endif /* !PTR_T */ -#if !defined (SBRK_DECLARED) +#if defined (HAVE_SBRK) && !defined (SBRK_DECLARED) extern char *sbrk(); #endif @@ -60,6 +60,19 @@ static size_t allocated; /* */ /* **************************************************************** */ +#if defined (HAVE_SBRK) +static size_t +findbrk () +{ + if (brkfound == 0) + { + lbreak = (PTR_T)sbrk (0); + brkfound++; + } + return (char *)sbrk (0) - (char *)lbreak; +} +#endif + /* Return a pointer to free()able block of memory large enough to hold BYTES number of bytes. If the memory cannot be allocated, print an error message and abort. */ @@ -73,13 +86,12 @@ xmalloc (bytes) if (temp == 0) { - if (brkfound == 0) - { - lbreak = (PTR_T)sbrk (0); - brkfound++; - } - allocated = (char *)sbrk (0) - (char *)lbreak; +#if defined (HAVE_SBRK) + allocated = findbrk (); fatal_error ("xmalloc: cannot allocate %lu bytes (%lu bytes allocated)", (unsigned long)bytes, (unsigned long)allocated); +#else + fatal_error ("xmalloc: cannot allocate %lu bytes", (unsigned long)bytes); +#endif /* !HAVE_SBRK */ } return (temp); @@ -96,13 +108,12 @@ xrealloc (pointer, bytes) if (temp == 0) { - if (brkfound == 0) - { - lbreak = (PTR_T)sbrk (0); - brkfound++; - } - allocated = (char *)sbrk (0) - (char *)lbreak; +#if defined (HAVE_SBRK) + allocated = findbrk (); fatal_error ("xrealloc: cannot reallocate %lu bytes (%lu bytes allocated)", (unsigned long)bytes, (unsigned long)allocated); +#else + fatal_error ("xmalloc: cannot allocate %lu bytes", (unsigned long)bytes); +#endif /* !HAVE_SBRK */ } return (temp); |