Updated with Tizen:Base source codes
[external/procps.git] / proc / alloc.c
1 // Copyright (C) 1992-1998 by Michael K. Johnson, johnsonm@redhat.com
2 // Copyright 2002 Albert Cahalan
3 //
4 // This file is placed under the conditions of the GNU Library
5 // General Public License, version 2, or any later version.
6 // See file COPYING for information on distribution conditions.
7
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include "alloc.h"
11
12 void *xcalloc(void *pointer, int size) {
13     void * ret;
14     if (pointer)
15         free(pointer);
16     if (!(ret = calloc(1, size))) {
17         fprintf(stderr, "xcalloc: allocation error, size = %d\n", size);
18         exit(1);
19     }
20     return ret;
21 }
22
23 void *xmalloc(unsigned int size) {
24     void *p;
25
26     if (size == 0)
27         ++size;
28     p = malloc(size);
29     if (!p) {
30         fprintf(stderr, "xmalloc: malloc(%d) failed", size);
31         perror(NULL);
32         exit(1);
33     }
34     return(p);
35 }
36
37 void *xrealloc(void *oldp, unsigned int size) {
38     void *p;
39
40     if (size == 0)
41         ++size;
42     p = realloc(oldp, size);
43     if (!p) {
44         fprintf(stderr, "xrealloc: realloc(%d) failed", size);
45         perror(NULL);
46         exit(1);
47     }
48     return(p);
49 }