/[gnats]/gnats/libiberty/xmalloc.c
ViewVC logotype

Diff of /gnats/libiberty/xmalloc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by jsm, Tue Oct 26 07:10:16 1999 UTC revision 1.3 by pdm, Mon Dec 10 23:03:26 2001 UTC
# Line 17  License along with libiberty; see the fi Line 17  License along with libiberty; see the fi
17  not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,  not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  Boston, MA 02111-1307, USA.  */  Boston, MA 02111-1307, USA.  */
19    
20    #ifdef HAVE_CONFIG_H
21    #include "config.h"
22    #endif
23  #include "ansidecl.h"  #include "ansidecl.h"
24  #include "libiberty.h"  #include "libiberty.h"
25    
# Line 61  xmalloc_set_program_name (s) Line 64  xmalloc_set_program_name (s)
64  #endif /* HAVE_SBRK */  #endif /* HAVE_SBRK */
65  }  }
66    
67    void
68    xmalloc_failed (size)
69         size_t size;
70    {
71    #ifdef HAVE_SBRK
72      extern char **environ;
73      size_t allocated;
74    
75      if (first_break != NULL)
76        allocated = (char *) sbrk (0) - first_break;
77      else
78        allocated = (char *) sbrk (0) - (char *) &environ;
79      fprintf (stderr,
80               "\n%s%sCannot allocate %lu bytes after allocating %lu bytes\n",
81               name, *name ? ": " : "",
82               (unsigned long) size, (unsigned long) allocated);
83    #else /* HAVE_SBRK */
84      fprintf (stderr,
85               "\n%s%sCannot allocate %lu bytes\n",
86               name, *name ? ": " : "",
87               (unsigned long) size);
88    #endif /* HAVE_SBRK */
89      xexit (1);
90    }  
91    
92  PTR  PTR
93  xmalloc (size)  xmalloc (size)
94      size_t size;      size_t size;
# Line 71  xmalloc (size) Line 99  xmalloc (size)
99      size = 1;      size = 1;
100    newmem = malloc (size);    newmem = malloc (size);
101    if (!newmem)    if (!newmem)
102      {      xmalloc_failed (size);
 #ifdef HAVE_SBRK  
       extern char **environ;  
       size_t allocated;  
103    
       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) size, (unsigned long) allocated);  
 #else /* HAVE_SBRK */  
       fprintf (stderr,  
               "\n%s%sCan not allocate %lu bytes\n",  
               name, *name ? ": " : "",  
               (unsigned long) size);  
 #endif /* HAVE_SBRK */  
       xexit (1);  
     }  
104    return (newmem);    return (newmem);
105  }  }
106    
# Line 106  xcalloc (nelem, elsize) Line 115  xcalloc (nelem, elsize)
115    
116    newmem = calloc (nelem, elsize);    newmem = calloc (nelem, elsize);
117    if (!newmem)    if (!newmem)
118      {      xmalloc_failed (nelem * elsize);
 #ifdef HAVE_SBRK  
       extern char **environ;  
       size_t allocated;  
119    
       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 /* HAVE_SBRK */  
       fprintf (stderr,  
               "\n%s%sCan not allocate %lu bytes\n",  
               name, *name ? ": " : "",  
               (unsigned long) (nelem * elsize));  
 #endif /* HAVE_SBRK */  
       xexit (1);  
     }  
120    return (newmem);    return (newmem);
121  }  }
122    
# Line 144  xrealloc (oldmem, size) Line 134  xrealloc (oldmem, size)
134    else    else
135      newmem = realloc (oldmem, size);      newmem = realloc (oldmem, size);
136    if (!newmem)    if (!newmem)
137      {      xmalloc_failed (size);
 #ifdef HAVE_SBRK  
       extern char **environ;  
       size_t allocated;  
138    
       if (first_break != NULL)  
         allocated = (char *) sbrk (0) - first_break;  
       else  
         allocated = (char *) sbrk (0) - (char *) &environ;  
       fprintf (stderr,  
                "\n%s%sCan not reallocate %lu bytes after allocating %lu bytes\n",  
                name, *name ? ": " : "",  
                (unsigned long) size, (unsigned long) allocated);  
 #else /* HAVE_SBRK */  
       fprintf (stderr,  
               "\n%s%sCan not reallocate %lu bytes\n",  
               name, *name ? ": " : "",  
               (unsigned long) size);  
 #endif /* HAVE_SBRK */  
       xexit (1);  
     }  
139    return (newmem);    return (newmem);
140  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26