Back to index

cell-binutils  2.17cvs20070401
Functions | Variables
xmalloc.c File Reference
#include "ansidecl.h"
#include "libiberty.h"
#include <stdio.h>
#include <stddef.h>

Go to the source code of this file.

Functions

void * malloc (size_t)
void * realloc (void *, size_t)
void * calloc (size_t, size_t)
void * sbrk (ptrdiff_t)
void xmalloc_set_program_name (const char *s)
void xmalloc_failed (size_t size)
PTR xmalloc (size_t size)
PTR xcalloc (size_t nelem, size_t elsize)
PTR xrealloc (PTR oldmem, size_t size)

Variables

static const char * name = ""

Function Documentation

void* calloc ( size_t  ,
size_t   
)

Definition at line 23 of file calloc.c.

{
  register PTR ptr;  

  if (nelem == 0 || elsize == 0)
    nelem = elsize = 1;
  
  ptr = malloc (nelem * elsize);
  if (ptr) bzero (ptr, nelem * elsize);
  
  return ptr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* malloc ( size_t  )
void* realloc ( void *  ,
size_t   
)
void* sbrk ( ptrdiff_t  )

Here is the caller graph for this function:

PTR xcalloc ( size_t  nelem,
size_t  elsize 
)

Definition at line 155 of file xmalloc.c.

{
  PTR newmem;

  if (nelem == 0 || elsize == 0)
    nelem = elsize = 1;

  newmem = calloc (nelem, elsize);
  if (!newmem)
    xmalloc_failed (nelem * elsize);

  return (newmem);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PTR xmalloc ( size_t  size)

Definition at line 141 of file xmalloc.c.

{
  PTR newmem;

  if (size == 0)
    size = 1;
  newmem = malloc (size);
  if (!newmem)
    xmalloc_failed (size);

  return (newmem);
}

Here is the call graph for this function:

void xmalloc_failed ( size_t  size)

Definition at line 117 of file xmalloc.c.

{
#ifdef HAVE_SBRK
  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%sout of memory allocating %lu bytes after a total of %lu bytes\n",
          name, *name ? ": " : "",
          (unsigned long) size, (unsigned long) allocated);
#else /* HAVE_SBRK */
  fprintf (stderr,
          "\n%s%sout of memory allocating %lu bytes\n",
          name, *name ? ": " : "",
          (unsigned long) size);
#endif /* HAVE_SBRK */
  xexit (1);
}  

Here is the call graph for this function:

Here is the caller graph for this function:

void xmalloc_set_program_name ( const char *  s)

Definition at line 106 of file xmalloc.c.

{
  name = s;
#ifdef HAVE_SBRK
  /* Win32 ports other than cygwin32 don't have brk() */
  if (first_break == NULL)
    first_break = (char *) sbrk (0);
#endif /* HAVE_SBRK */
}

Here is the call graph for this function:

Here is the caller graph for this function:

PTR xrealloc ( PTR  oldmem,
size_t  size 
)

Definition at line 170 of file xmalloc.c.

{
  PTR newmem;

  if (size == 0)
    size = 1;
  if (!oldmem)
    newmem = malloc (size);
  else
    newmem = realloc (oldmem, size);
  if (!newmem)
    xmalloc_failed (size);

  return (newmem);
}

Here is the call graph for this function:


Variable Documentation

const char* name = "" [static]

Definition at line 97 of file xmalloc.c.