File: xrealloc.c

package info (click to toggle)
icmake 7.21.01-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,856 kB
  • ctags: 1,498
  • sloc: ansic: 7,791; makefile: 3,879; sh: 320; cpp: 83
file content (46 lines) | stat: -rw-r--r-- 1,066 bytes parent folder | download | duplicates (4)
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
/*
\funcref{xrealloc}{VOIDP xrealloc (\params)}
    {
        {VOIDP} {ptr} {pointer to previously allocated memory, or NULL}
        {int} {size} {new requested size, or 0}
    }
    {pointer to reallocated memory}
    {error()}
    {xstrdup()}
    {xrealloc.c}
    {
        {\em xrealloc()} attempts to reallocate the memory pointed to by {\em
        ptr}. If {\em ptr} is NULL, {\em xrealloc()} simply behaves like {\em
        malloc()}. When allocation indicates failure, {\em error()} is called
        to terminate the program with an appropriate message.

        The new requested size may be zero. In this case, {\em xrealloc()}
        frees the memory associated with {\em ptr}.
    }
*/


#include "icrssdef.h"

void *xrealloc (void *ptr, size_t size)
{
    register void
        *newptr;

    if (! size)
    {
        if (ptr)
            free (ptr);
        return (NULL);
    }

    if (ptr)
        newptr = realloc (ptr, size);
    else
        newptr = malloc (size);

    if (! newptr)
        error ("out of memory");

    return (newptr);
}