1REALLOC(P)                 POSIX Programmer's Manual                REALLOC(P)
2
3
4

NAME

6       realloc - memory reallocator
7

SYNOPSIS

9       #include <stdlib.h>
10
11       void *realloc(void *ptr, size_t size);
12
13

DESCRIPTION

15       The  realloc()  function  shall  change  the  size of the memory object
16       pointed to by ptr to the size specified by size. The  contents  of  the
17       object  shall  remain  unchanged  up  to  the lesser of the new and old
18       sizes. If the new size of the memory object would require  movement  of
19       the  object,  the space for the previous instantiation of the object is
20       freed. If the new size is larger, the contents of the  newly  allocated
21       portion  of  the  object are unspecified. If size is 0 and ptr is not a
22       null pointer, the object pointed to is freed. If the  space  cannot  be
23       allocated, the object shall remain unchanged.
24
25       If ptr is a null pointer, realloc() shall be equivalent to malloc() for
26       the specified size.
27
28       If ptr does not match a pointer returned earlier by calloc(), malloc(),
29       or  realloc() or if the space has previously been deallocated by a call
30       to free() or realloc(), the behavior is undefined.
31
32       The order and contiguity of storage allocated by  successive  calls  to
33       realloc()  is  unspecified. The pointer returned if the allocation suc‐
34       ceeds shall be suitably aligned so that it may be assigned to a pointer
35       to  any  type  of  object and then used to access such an object in the
36       space allocated (until the space is explicitly freed  or  reallocated).
37       Each  such  allocation shall yield a pointer to an object disjoint from
38       any other object. The pointer returned shall point to the start (lowest
39       byte address) of the allocated space. If the space cannot be allocated,
40       a null pointer shall be returned.
41

RETURN VALUE

43       Upon successful completion with a size not equal to 0, realloc()  shall
44       return a pointer to the (possibly moved) allocated space. If size is 0,
45       either a null pointer or a unique  pointer  that  can  be  successfully
46       passed  to  free() shall be returned.  If there is not enough available
47       memory, realloc() shall return a  null  pointer     and  set  errno  to
48       [ENOMEM].
49

ERRORS

51       The realloc() function shall fail if:
52
53       ENOMEM Insufficient memory is available.
54
55
56       The following sections are informative.
57

EXAMPLES

59       None.
60

APPLICATION USAGE

62       None.
63

RATIONALE

65       None.
66

FUTURE DIRECTIONS

68       None.
69

SEE ALSO

71       calloc()  ,  free()  ,  malloc()  ,  the  Base  Definitions  volume  of
72       IEEE Std 1003.1-2001, <stdlib.h>
73
75       Portions of this text are reprinted and reproduced in  electronic  form
76       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
77       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
78       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
79       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
80       event of any discrepancy between this version and the original IEEE and
81       The Open Group Standard, the original IEEE and The Open Group  Standard
82       is  the  referee document. The original Standard can be obtained online
83       at http://www.opengroup.org/unix/online.html .
84
85
86
87IEEE/The Open Group                  2003                           REALLOC(P)
Impressum