Commit a9acf741 by Kaveh R. Ghazi Committed by Kaveh Ghazi

configure.in: Check for calloc.

        * configure.in: Check for calloc.
        * calloc.c: New file.
        * xmalloc.c (xcalloc): New function.

From-SVN: r23642
parent 67d0f6ab
Fri Nov 13 19:18:05 1998 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* configure.in: Check for calloc.
* calloc.c: New file.
* xmalloc.c (xcalloc): New function.
Fri Nov 13 08:51:46 EST 1998 Andrew MacLeod <amacleod@cygnus.com>
*cplus-dem.c (demangle_prefix): Use the last "__"
......
#include "ansidecl.h"
#include "libiberty.h"
#ifdef ANSI_PROTOTYPES
#include <stddef.h>
#else
#define size_t unsigned long
#endif
/* For systems with larger pointers than ints, this must be declared. */
PTR malloc PARAMS ((size_t));
PTR
calloc (nelem, elsize)
size_t nelem, elsize;
{
register PTR ptr;
if (nelem == 0 || elsize == 0)
nelem = elsize = 1;
ptr = malloc (nelem * elsize);
if (ptr) bzero (ptr, nelem * elsize);
return ptr;
}
......@@ -117,6 +117,7 @@ funcs="$funcs basename"
funcs="$funcs bcmp"
funcs="$funcs bcopy"
funcs="$funcs bzero"
funcs="$funcs calloc"
funcs="$funcs clock"
funcs="$funcs getcwd"
funcs="$funcs getpagesize"
......@@ -156,7 +157,7 @@ checkfuncs="getrusage on_exit psignal strerror strsignal sysconf times"
# These are neither executed nor required, but they help keep
# autoheader happy without adding a bunch of text to acconfig.h.
if test "x" = "y"; then
AC_CHECK_FUNCS(asprintf atexit basename bcmp bcopy bzero clock getcwd)
AC_CHECK_FUNCS(asprintf atexit basename bcmp bcopy bzero calloc clock getcwd)
AC_CHECK_FUNCS(getpagesize index insque memchr memcmp memcpy memmove)
AC_CHECK_FUNCS(memset random rename rindex sigsetmask strcasecmp)
AC_CHECK_FUNCS(strchr strdup strncasecmp strrchr strstr strtod strtol)
......
......@@ -36,6 +36,7 @@ Boston, MA 02111-1307, USA. */
/* For systems with larger pointers than ints, these must be declared. */
PTR malloc PARAMS ((size_t));
PTR realloc PARAMS ((PTR, size_t));
PTR calloc PARAMS ((size_t, size_t));
PTR sbrk PARAMS ((ptrdiff_t));
#endif
......@@ -95,6 +96,41 @@ xmalloc (size)
}
PTR
xcalloc (nelem, elsize)
size_t nelem, elsize;
{
PTR newmem;
if (nelem == 0 || elsize == 0)
nelem = elsize = 1;
newmem = calloc (nelem, elsize);
if (!newmem)
{
#if ! defined (_WIN32) || defined (__CYGWIN32__)
extern char **environ;
size_t allocated;
if (first_break != NULL)
allocated = (char *) sbrk (0) - first_break;
else
allocated = (char *) sbrk (0) - (char *) &environ;
fprintf (stderr,
"\n%s%sCan not allocate %lu bytes after allocating %lu bytes\n",
name, *name ? ": " : "",
(unsigned long) (nelem * elsize), (unsigned long) allocated);
#else
fprintf (stderr,
"\n%s%sCan not allocate %lu bytes\n",
name, *name ? ": " : "",
(unsigned long) (nelem * elsize));
#endif /* ! _WIN32 || __CYGWIN32 __ */
xexit (1);
}
return (newmem);
}
PTR
xrealloc (oldmem, size)
PTR oldmem;
size_t size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment