File: alloc.c

package info (click to toggle)
procps 1%3A2.0.6-5
  • links: PTS
  • area: main
  • in suites: potato
  • size: 932 kB
  • ctags: 1,146
  • sloc: ansic: 10,494; makefile: 229; sh: 80
file content (49 lines) | stat: -rw-r--r-- 1,196 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/***********************************************************************\
*   Copyright (C) 1992-1998 by Michael K. Johnson, johnsonm@redhat.com  *
*									*
*	This file is placed under the conditions of the GNU Library	*
*	General Public License, version 2, or any later version.	*
*	See file COPYING for information on distribution conditions.	*
\***********************************************************************/
#include <stdlib.h>
#include <stdio.h>

void *xcalloc(void *pointer, int size) {
    void * ret;
    if (pointer)
        free(pointer);
    if (!(ret = calloc(1, size))) {
        fprintf(stderr, "xcalloc: allocation error, size = %d\n", size);
        exit(1);
    } else {
        return ret;
    }
}

void *xmalloc(unsigned int size) {
    void *p;

    if (size == 0)
        ++size;
    p = malloc(size);
    if (!p) {
	fprintf(stderr, "xmalloc: malloc(%d) failed", size);
	perror(NULL);
	exit(1);
    }
    return(p);
}

void *xrealloc(void *oldp, unsigned int size) {
    void *p;

    if (size == 0)
        ++size;
    p = realloc(oldp, size);
    if (!p) {
	fprintf(stderr, "xrealloc: realloc(%d) failed", size);
	perror(NULL);
	exit(1);
    }
    return(p);
}