Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/libiberty/xmalloc.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    1818Boston, MA 02111-1307, USA.  */
    1919
     20/*
     21
     22@deftypefn Replacement void* xmalloc (size_t)
     23
     24Allocate memory without fail.  If @code{malloc} fails, this will print
     25a message to @code{stderr} (using the name set by
     26@code{xmalloc_set_program_name},
     27if any) and then call @code{xexit}.  Note that it is therefore safe for
     28a program to contain @code{#define malloc xmalloc} in its source.
     29
     30@end deftypefn
     31
     32@deftypefn Replacement void* xrealloc (void *@var{ptr}, size_t @var{size})
     33Reallocate memory without fail.  This routine functions like @code{realloc},
     34but will behave the same as @code{xmalloc} if memory cannot be found.
     35
     36@end deftypefn
     37
     38@deftypefn Replacement void* xcalloc (size_t @var{nelem}, size_t @var{elsize})
     39
     40Allocate memory without fail, and set it to zero.  This routine functions
     41like @code{calloc}, but will behave the same as @code{xmalloc} if memory
     42cannot be found.
     43
     44@end deftypefn
     45
     46@deftypefn Replacement void xmalloc_set_program_name (const char *@var{name})
     47
     48You can use this to set the name of the program used by
     49@code{xmalloc_failed} when printing a failure message.
     50
     51@end deftypefn
     52
     53@deftypefn Replacement void xmalloc_failed (size_t)
     54
     55This function is not meant to be called by client code, and is listed
     56here for completeness only.  If any of the allocation routines fail, this
     57function will be called to print an error message and terminate execution.
     58
     59@end deftypefn
     60
     61*/
     62
    2063#ifdef HAVE_CONFIG_H
    2164#include "config.h"
     
    2669#include <stdio.h>
    2770
    28 #ifdef __STDC__
     71#ifdef ANSI_PROTOTYPES
    2972#include <stddef.h>
    3073#else
     
    78121    allocated = (char *) sbrk (0) - (char *) &environ;
    79122  fprintf (stderr,
    80            "\n%s%sCannot allocate %lu bytes after allocating %lu bytes\n",
     123           "\n%s%sout of memory allocating %lu bytes after a total of %lu bytes\n",
    81124           name, *name ? ": " : "",
    82125           (unsigned long) size, (unsigned long) allocated);
    83126#else /* HAVE_SBRK */
    84127  fprintf (stderr,
    85            "\n%s%sCannot allocate %lu bytes\n",
     128           "\n%s%sout of memory allocating %lu bytes\n",
    86129           name, *name ? ": " : "",
    87130           (unsigned long) size);
Note: See TracChangeset for help on using the changeset viewer.