diff options
| author | tholo <> | 1996-08-10 04:18:49 +0000 |
|---|---|---|
| committer | tholo <> | 1996-08-10 04:18:49 +0000 |
| commit | cc20851f7c7e8c47582db29709f2c1f2726cc0ec (patch) | |
| tree | 9f8277db909d533c2a42e25b93e12f1f14907cf2 /src/lib/libc/stdlib | |
| parent | 81262c3c4515a67e0c45a334c3212fb1c5de4b7e (diff) | |
| download | openbsd-cc20851f7c7e8c47582db29709f2c1f2726cc0ec.tar.gz openbsd-cc20851f7c7e8c47582db29709f2c1f2726cc0ec.tar.bz2 openbsd-cc20851f7c7e8c47582db29709f2c1f2726cc0ec.zip | |
Import malloc(3) manual page from FreeBSD
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/stdlib/Makefile.inc | 15 | ||||
| -rw-r--r-- | src/lib/libc/stdlib/free.3 | 82 | ||||
| -rw-r--r-- | src/lib/libc/stdlib/malloc.3 | 138 | ||||
| -rw-r--r-- | src/lib/libc/stdlib/realloc.3 | 100 |
4 files changed, 127 insertions, 208 deletions
diff --git a/src/lib/libc/stdlib/Makefile.inc b/src/lib/libc/stdlib/Makefile.inc index 625f0f9a91..6c635ef354 100644 --- a/src/lib/libc/stdlib/Makefile.inc +++ b/src/lib/libc/stdlib/Makefile.inc | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | # from: @(#)Makefile.inc 5.6 (Berkeley) 6/4/91 | 1 | # $OpenBSD: Makefile.inc,v 1.3 1996/08/10 04:18:48 tholo Exp $ |
| 2 | # $Id: Makefile.inc,v 1.2 1996/03/25 23:31:43 tholo Exp $ | ||
| 3 | 2 | ||
| 4 | # stdlib sources | 3 | # stdlib sources |
| 5 | .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/stdlib ${.CURDIR}/stdlib | 4 | .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/stdlib ${.CURDIR}/stdlib |
| @@ -33,17 +32,17 @@ SRCS+= abs.c div.c labs.c ldiv.c | |||
| 33 | .endif | 32 | .endif |
| 34 | 33 | ||
| 35 | MAN+= abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \ | 34 | MAN+= abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \ |
| 36 | calloc.3 div.3 exit.3 free.3 getenv.3 getopt.3 labs.3 ldiv.3 \ | 35 | calloc.3 div.3 exit.3 getenv.3 getopt.3 labs.3 ldiv.3 malloc.3 \ |
| 37 | malloc.3 memory.3 qabs.3 qdiv.3 qsort.3 radixsort.3 rand48.3 \ | 36 | memory.3 qabs.3 qdiv.3 qsort.3 radixsort.3 rand48.3 rand.3 \ |
| 38 | rand.3 random.3 realloc.3 realpath.3 strtod.3 strtol.3 strtoul.3 \ | 37 | random.3 realpath.3 strtod.3 strtol.3 strtoul.3 system.3 |
| 39 | system.3 | ||
| 40 | 38 | ||
| 41 | MLINKS+=getenv.3 setenv.3 getenv.3 unsetenv.3 getenv.3 putenv.3 | 39 | MLINKS+=getenv.3 setenv.3 getenv.3 unsetenv.3 getenv.3 putenv.3 |
| 40 | MLINKS+=malloc.3 free.3 malloc.3 realloc.3 | ||
| 42 | MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3 | 41 | MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3 |
| 43 | MLINKS+=rand.3 srand.3 | 42 | MLINKS+=rand.3 srand.3 |
| 44 | MLINKS+=strtol.3 strtoq.3 | ||
| 45 | MLINKS+=strtoul.3 strtouq.3 | ||
| 46 | MLINKS+=random.3 initstate.3 random.3 setstate.3 random.3 srandom.3 | 43 | MLINKS+=random.3 initstate.3 random.3 setstate.3 random.3 srandom.3 |
| 47 | MLINKS+=rand48.3 drand48.3 rand48.3 erand48.3 rand48.3 lrand48.3 | 44 | MLINKS+=rand48.3 drand48.3 rand48.3 erand48.3 rand48.3 lrand48.3 |
| 48 | MLINKS+=rand48.3 mrand48.3 rand48.3 nrand48.3 rand48.3 jrand48.3 | 45 | MLINKS+=rand48.3 mrand48.3 rand48.3 nrand48.3 rand48.3 jrand48.3 |
| 49 | MLINKS+=rand48.3 srand48.3 rand48.3 seed48.3 rand48.3 lcong48.3 | 46 | MLINKS+=rand48.3 srand48.3 rand48.3 seed48.3 rand48.3 lcong48.3 |
| 47 | MLINKS+=strtol.3 strtoq.3 | ||
| 48 | MLINKS+=strtoul.3 strtouq.3 | ||
diff --git a/src/lib/libc/stdlib/free.3 b/src/lib/libc/stdlib/free.3 deleted file mode 100644 index 3d0131d7de..0000000000 --- a/src/lib/libc/stdlib/free.3 +++ /dev/null | |||
| @@ -1,82 +0,0 @@ | |||
| 1 | .\" Copyright (c) 1991 The Regents of the University of California. | ||
| 2 | .\" All rights reserved. | ||
| 3 | .\" | ||
| 4 | .\" This code is derived from software contributed to Berkeley by | ||
| 5 | .\" the American National Standards Committee X3, on Information | ||
| 6 | .\" Processing Systems. | ||
| 7 | .\" | ||
| 8 | .\" Redistribution and use in source and binary forms, with or without | ||
| 9 | .\" modification, are permitted provided that the following conditions | ||
| 10 | .\" are met: | ||
| 11 | .\" 1. Redistributions of source code must retain the above copyright | ||
| 12 | .\" notice, this list of conditions and the following disclaimer. | ||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | .\" notice, this list of conditions and the following disclaimer in the | ||
| 15 | .\" documentation and/or other materials provided with the distribution. | ||
| 16 | .\" 3. All advertising materials mentioning features or use of this software | ||
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | ||
| 22 | .\" without specific prior written permission. | ||
| 23 | .\" | ||
| 24 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 25 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 26 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 27 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 28 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 29 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 30 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 31 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 32 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 34 | .\" SUCH DAMAGE. | ||
| 35 | .\" | ||
| 36 | .\" from: @(#)free.3 5.2 (Berkeley) 6/29/91 | ||
| 37 | .\" $Id: free.3,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp $ | ||
| 38 | .\" | ||
| 39 | .Dd June 29, 1991 | ||
| 40 | .Dt FREE 3 | ||
| 41 | .Os | ||
| 42 | .Sh NAME | ||
| 43 | .Nm free | ||
| 44 | .Nd free up memory allocated with malloc, calloc or realloc | ||
| 45 | .Sh SYNOPSIS | ||
| 46 | .Fd #include <stdlib.h> | ||
| 47 | .Ft void | ||
| 48 | .Fn free "void *ptr" | ||
| 49 | .Sh DESCRIPTION | ||
| 50 | The | ||
| 51 | .Fn free | ||
| 52 | function causes the space pointed to by | ||
| 53 | .Fa ptr | ||
| 54 | to be deallocated, that is, made available | ||
| 55 | for further allocation. | ||
| 56 | If | ||
| 57 | .Fa ptr | ||
| 58 | is a null pointer, no action occurs. | ||
| 59 | Otherwise, if the argument does not match a pointer earlier | ||
| 60 | returned by the | ||
| 61 | .Xr calloc , | ||
| 62 | .Xr malloc , | ||
| 63 | or | ||
| 64 | .Xr realloc | ||
| 65 | function, or if the space has been deallocated by a call to | ||
| 66 | .Fn free | ||
| 67 | or | ||
| 68 | .Xr realloc , | ||
| 69 | general havoc may occur. | ||
| 70 | .Sh RETURN VALUES | ||
| 71 | The | ||
| 72 | .Fn free | ||
| 73 | function returns no value. | ||
| 74 | .Sh SEE ALSO | ||
| 75 | .Xr calloc 3 , | ||
| 76 | .Xr malloc 3 , | ||
| 77 | .Xr realloc 3 | ||
| 78 | .Sh STANDARDS | ||
| 79 | The | ||
| 80 | .Fn free | ||
| 81 | function conforms to | ||
| 82 | .St -ansiC . | ||
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3 index 3bbf2bf65e..b6acd64854 100644 --- a/src/lib/libc/stdlib/malloc.3 +++ b/src/lib/libc/stdlib/malloc.3 | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | .\" Copyright (c) 1980, 1991 Regents of the University of California. | 1 | .\" Copyright (c) 1980, 1991, 1993 |
| 2 | .\" All rights reserved. | 2 | .\" The Regents of the University of California. All rights reserved. |
| 3 | .\" | 3 | .\" |
| 4 | .\" This code is derived from software contributed to Berkeley by | 4 | .\" This code is derived from software contributed to Berkeley by |
| 5 | .\" the American National Standards Committee X3, on Information | 5 | .\" the American National Standards Committee X3, on Information |
| @@ -33,19 +33,28 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)malloc.3 6.7 (Berkeley) 6/29/91 | 36 | .\" $OpenBSD: malloc.3,v 1.2 1996/08/10 04:18:49 tholo Exp $ |
| 37 | .\" $Id: malloc.3,v 1.1.1.1 1995/10/18 08:42:18 deraadt Exp $ | ||
| 38 | .\" | 37 | .\" |
| 39 | .Dd June 29, 1991 | 38 | .Dd June 4, 1993 |
| 40 | .Dt MALLOC 3 | 39 | .Dt MALLOC 3 |
| 41 | .Os BSD 4 | 40 | .Os BSD 4 |
| 42 | .Sh NAME | 41 | .Sh NAME |
| 43 | .Nm malloc | 42 | .Nm malloc , |
| 44 | .Nd general memory allocation function | 43 | .Nd general memory allocation function |
| 44 | .Pp | ||
| 45 | .Nm free | ||
| 46 | .Nd free up memory allocated with malloc, calloc or realloc | ||
| 47 | .Pp | ||
| 48 | .Nm realloc | ||
| 49 | .Nd reallocation of memory function | ||
| 45 | .Sh SYNOPSIS | 50 | .Sh SYNOPSIS |
| 46 | .Fd #include <stdlib.h> | 51 | .Fd #include <stdlib.h> |
| 47 | .Ft void * | 52 | .Ft void * |
| 48 | .Fn malloc "size_t size" | 53 | .Fn malloc "size_t size" |
| 54 | .Ft void | ||
| 55 | .Fn free "void *ptr" | ||
| 56 | .Ft void * | ||
| 57 | .Fn realloc "void *ptr" "size_t size" | ||
| 49 | .Sh DESCRIPTION | 58 | .Sh DESCRIPTION |
| 50 | The | 59 | The |
| 51 | .Fn malloc | 60 | .Fn malloc |
| @@ -62,30 +71,123 @@ suitably aligned (after possible pointer | |||
| 62 | coercion) for storage of any type of object. If the space is of | 71 | coercion) for storage of any type of object. If the space is of |
| 63 | .Em pagesize | 72 | .Em pagesize |
| 64 | or larger, the memory returned will be page-aligned. | 73 | or larger, the memory returned will be page-aligned. |
| 74 | .Pp | ||
| 75 | The | ||
| 76 | .Fn free | ||
| 77 | function causes the space pointed to by | ||
| 78 | .Fa ptr | ||
| 79 | to be deallocated, that is, at least made available for further allocation, | ||
| 80 | but if possible, it will passed back to the kernel with | ||
| 81 | .Xr sbrk 2 . | ||
| 82 | If | ||
| 83 | .Fa ptr | ||
| 84 | is a null pointer, no action occurs. | ||
| 85 | .Pp | ||
| 86 | The | ||
| 87 | .Fn realloc | ||
| 88 | function changes the size of the object pointed to by | ||
| 89 | .Fa ptr | ||
| 90 | to the size specified by | ||
| 91 | .Fa size . | ||
| 92 | The contents of the object are unchanged up to the lesser | ||
| 93 | of the new and old sizes. | ||
| 94 | If the new size is larger, the value of the newly allocated portion | ||
| 95 | of the object is indeterminate. | ||
| 96 | If | ||
| 97 | .Fa ptr | ||
| 98 | is a null pointer, the | ||
| 99 | .Fn realloc | ||
| 100 | function behaves like the | ||
| 101 | .Fn malloc | ||
| 102 | function for the specified size. | ||
| 103 | If the space cannot be allocated, the object | ||
| 104 | pointed to by | ||
| 105 | .Fa ptr | ||
| 106 | is unchanged. | ||
| 107 | If | ||
| 108 | .Fa size | ||
| 109 | is zero and | ||
| 110 | .Fa ptr | ||
| 111 | is not a null pointer, the object it points to is freed. | ||
| 112 | .Pp | ||
| 113 | |||
| 114 | .Sh ENVIRONMENT | ||
| 115 | This malloc will check the environment for a variable called | ||
| 116 | .Em MALLOC_OPTIONS | ||
| 117 | and scan it for flags. | ||
| 118 | Flags are single letters, uppercase means on, lowercase means off. | ||
| 119 | .Bl -tag -width indent | ||
| 120 | .It A | ||
| 121 | ``abort'' malloc will coredump the process, rather than tolerate failure. | ||
| 122 | This is a very handy debugging aid, since the core file will represent the | ||
| 123 | time of failure, | ||
| 124 | rather than when the NULL pointer was accessed. | ||
| 125 | |||
| 126 | .It D | ||
| 127 | ``dump'' malloc will dump statistics in a file called ``malloc.out'' at exit. | ||
| 128 | This option requires the library to have been compiled with -DMALLOC_STATS in | ||
| 129 | order to have any effect. | ||
| 130 | |||
| 131 | .It J | ||
| 132 | ``junk'' fill some junk into the area allocated. | ||
| 133 | Currently junk is bytes of 0xd0, this is pronounced ``Duh'' :-) | ||
| 134 | |||
| 135 | .It R | ||
| 136 | ``realloc'' always reallocate when | ||
| 137 | .Fn realloc | ||
| 138 | is called, even if the initial allocation was big enough. | ||
| 139 | This can substantially aid in compacting memory. | ||
| 140 | |||
| 141 | .It Z | ||
| 142 | ``zero'' fill some junk into the area allocated (see ``J''), | ||
| 143 | except for the exact length the user asked for, which is zeroed. | ||
| 144 | |||
| 145 | .El | ||
| 146 | .Pp | ||
| 147 | The ``J'' and ``Z'' is mostly for testing and debugging, | ||
| 148 | if a program changes behavior if either of these options are used, | ||
| 149 | it is buggy. | ||
| 65 | .Sh RETURN VALUES | 150 | .Sh RETURN VALUES |
| 66 | The | 151 | The |
| 67 | .Fn malloc | 152 | .Fn malloc |
| 68 | function returns | 153 | function returns |
| 69 | a pointer to the allocated space if successful; otherwise | 154 | a pointer to the allocated space if successful; otherwise |
| 70 | a null pointer is returned. | 155 | a null pointer is returned. |
| 156 | .Pp | ||
| 157 | The | ||
| 158 | .Fn free | ||
| 159 | function returns no value. | ||
| 160 | .Pp | ||
| 161 | The | ||
| 162 | .Fn realloc | ||
| 163 | function returns either a null pointer or a pointer | ||
| 164 | to the possibly moved allocated space. | ||
| 71 | .Sh SEE ALSO | 165 | .Sh SEE ALSO |
| 72 | .Xr brk 2 , | 166 | .Xr brk 2 , |
| 73 | .Xr getpagesize 2 , | ||
| 74 | .Xr free 3 , | ||
| 75 | .Xr calloc 3 , | ||
| 76 | .Xr alloca 3 , | 167 | .Xr alloca 3 , |
| 77 | .Xr realloc 3 , | 168 | .Xr calloc 3 , |
| 169 | .Xr getpagesize 3 , | ||
| 78 | .Xr memory 3 | 170 | .Xr memory 3 |
| 79 | .Sh STANDARDS | 171 | .Sh STANDARDS |
| 80 | The | 172 | The |
| 81 | .Fn malloc | 173 | .Fn malloc |
| 82 | function conforms to | 174 | function conforms to |
| 83 | .St -ansiC . | 175 | .St -ansiC . |
| 84 | .Sh BUGS | 176 | .Sh HISTORY |
| 85 | The current implementation of | 177 | The present implementation of malloc started out as a filesystem on a drum |
| 86 | .Xr malloc | 178 | attached to a 20bit binary challenged computer built with discrete germanium |
| 87 | does not always fail gracefully when system | 179 | transistors, and it has since graduated to handle primary storage rather than |
| 88 | memory limits are approached. | 180 | secondary. |
| 89 | It may fail to allocate memory when larger free blocks could be broken | 181 | .Pp |
| 90 | up, or when limits are exceeded because the size is rounded up. | 182 | The main difference from other malloc implementations are believed to be that |
| 91 | It is optimized for sizes that are powers of two. | 183 | the free pages are not accessed until allocated. |
| 184 | Most malloc implementations will store a data structure containing a, | ||
| 185 | possibly double-, linked list in the free chunks of memory, used to tie | ||
| 186 | all the free memory together. | ||
| 187 | That is a quite suboptimal thing to do. | ||
| 188 | Every time the free-list is traversed, all the otherwise unused, and very | ||
| 189 | likely paged out, pages get faulted into primary memory, just to see what | ||
| 190 | lies after them in the list. | ||
| 191 | .Pp | ||
| 192 | On systems which are paging, this can make a factor five in difference on the | ||
| 193 | page-faults of a process. | ||
diff --git a/src/lib/libc/stdlib/realloc.3 b/src/lib/libc/stdlib/realloc.3 deleted file mode 100644 index 66f09b2081..0000000000 --- a/src/lib/libc/stdlib/realloc.3 +++ /dev/null | |||
| @@ -1,100 +0,0 @@ | |||
| 1 | .\" Copyright (c) 1991 The Regents of the University of California. | ||
| 2 | .\" All rights reserved. | ||
| 3 | .\" | ||
| 4 | .\" Redistribution and use in source and binary forms, with or without | ||
| 5 | .\" modification, are permitted provided that the following conditions | ||
| 6 | .\" are met: | ||
| 7 | .\" 1. Redistributions of source code must retain the above copyright | ||
| 8 | .\" notice, this list of conditions and the following disclaimer. | ||
| 9 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
| 10 | .\" notice, this list of conditions and the following disclaimer in the | ||
| 11 | .\" documentation and/or other materials provided with the distribution. | ||
| 12 | .\" 3. All advertising materials mentioning features or use of this software | ||
| 13 | .\" must display the following acknowledgement: | ||
| 14 | .\" This product includes software developed by the University of | ||
| 15 | .\" California, Berkeley and its contributors. | ||
| 16 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 17 | .\" may be used to endorse or promote products derived from this software | ||
| 18 | .\" without specific prior written permission. | ||
| 19 | .\" | ||
| 20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 30 | .\" SUCH DAMAGE. | ||
| 31 | .\" | ||
| 32 | .\" from: @(#)realloc.3 5.1 (Berkeley) 5/2/91 | ||
| 33 | .\" $Id: realloc.3,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $ | ||
| 34 | .\" | ||
| 35 | .Dd May 2, 1991 | ||
| 36 | .Dt REALLOC 3 | ||
| 37 | .Os | ||
| 38 | .Sh NAME | ||
| 39 | .Nm realloc | ||
| 40 | .Nd reallocation of memory function | ||
| 41 | .Sh SYNOPSIS | ||
| 42 | .Fd #include <stdlib.h> | ||
| 43 | .Ft void * | ||
| 44 | .Fn realloc "void *ptr" "size_t size" | ||
| 45 | .Sh DESCRIPTION | ||
| 46 | The | ||
| 47 | .Fn realloc | ||
| 48 | function changes the size of the object pointed to by | ||
| 49 | .Fa ptr | ||
| 50 | to the size specified by | ||
| 51 | .Fa size . | ||
| 52 | The contents of the object are unchanged up to the lesser | ||
| 53 | of the new and old sizes. | ||
| 54 | If the new size is larger, the value of the newly allocated portion | ||
| 55 | of the object is indeterminate. | ||
| 56 | If | ||
| 57 | .Fa ptr | ||
| 58 | is a null pointer, the | ||
| 59 | .Fn realloc | ||
| 60 | function behaves like the | ||
| 61 | .Xr malloc 3 | ||
| 62 | function for the specified size. | ||
| 63 | Otherwise, if | ||
| 64 | .Fa ptr | ||
| 65 | does not match a pointer earlier returned by the | ||
| 66 | .Xr calloc 3 , | ||
| 67 | .Xr malloc 3 , | ||
| 68 | or | ||
| 69 | .Fn realloc | ||
| 70 | function, or if the space has been deallocated | ||
| 71 | by a call to the | ||
| 72 | .Xr free | ||
| 73 | or | ||
| 74 | .Fn realloc | ||
| 75 | function, unpredictable and usually detrimental | ||
| 76 | behavior will occur. | ||
| 77 | If the space cannot be allocated, the object | ||
| 78 | pointed to by | ||
| 79 | .Fa ptr | ||
| 80 | is unchanged. | ||
| 81 | If | ||
| 82 | .Fa size | ||
| 83 | is zero and | ||
| 84 | .Fa ptr | ||
| 85 | is not a null pointer, the object it points to is freed. | ||
| 86 | .Pp | ||
| 87 | The | ||
| 88 | .Fn realloc | ||
| 89 | function returns either a null pointer or a pointer | ||
| 90 | to the possibly moved allocated space. | ||
| 91 | .Sh SEE ALSO | ||
| 92 | .Xr alloca 3 , | ||
| 93 | .Xr calloc 3 , | ||
| 94 | .Xr free 3 , | ||
| 95 | .Xr malloc 3 , | ||
| 96 | .Sh STANDARDS | ||
| 97 | The | ||
| 98 | .Fn realloc | ||
| 99 | function conforms to | ||
| 100 | .St -ansiC . | ||
