diff options
| author | aaron <> | 1999-11-09 22:12:36 +0000 |
|---|---|---|
| committer | aaron <> | 1999-11-09 22:12:36 +0000 |
| commit | 804f568be8b94c5d121b519265452c56bd2efb50 (patch) | |
| tree | 8e8983be58be19c795441fe752c4a3b616216b09 /src/lib/libc/stdlib | |
| parent | 5d55745080b705a4223d109d1dbbd95cf1072a73 (diff) | |
| download | openbsd-804f568be8b94c5d121b519265452c56bd2efb50.tar.gz openbsd-804f568be8b94c5d121b519265452c56bd2efb50.tar.bz2 openbsd-804f568be8b94c5d121b519265452c56bd2efb50.zip | |
Merge calloc(3) man page into malloc.3; as suggested by millert@
Diffstat (limited to 'src/lib/libc/stdlib')
| -rw-r--r-- | src/lib/libc/stdlib/Makefile.inc | 4 | ||||
| -rw-r--r-- | src/lib/libc/stdlib/calloc.3 | 70 | ||||
| -rw-r--r-- | src/lib/libc/stdlib/malloc.3 | 57 |
3 files changed, 41 insertions, 90 deletions
diff --git a/src/lib/libc/stdlib/Makefile.inc b/src/lib/libc/stdlib/Makefile.inc index b1c20d08cd..9765082276 100644 --- a/src/lib/libc/stdlib/Makefile.inc +++ b/src/lib/libc/stdlib/Makefile.inc | |||
| @@ -33,12 +33,12 @@ SRCS+= abs.c div.c labs.c ldiv.c | |||
| 33 | .endif | 33 | .endif |
| 34 | 34 | ||
| 35 | MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \ | 35 | MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \ |
| 36 | calloc.3 div.3 exit.3 getenv.3 getopt.3 getsubopt.3 labs.3 ldiv.3 \ | 36 | div.3 exit.3 getenv.3 getopt.3 getsubopt.3 labs.3 ldiv.3 \ |
| 37 | malloc.3 memory.3 qabs.3 qdiv.3 qsort.3 radixsort.3 rand48.3 rand.3 \ | 37 | malloc.3 memory.3 qabs.3 qdiv.3 qsort.3 radixsort.3 rand48.3 rand.3 \ |
| 38 | random.3 realpath.3 strtod.3 strtol.3 strtoul.3 system.3 tsearch.3 | 38 | random.3 realpath.3 strtod.3 strtol.3 strtoul.3 system.3 tsearch.3 |
| 39 | 39 | ||
| 40 | MLINKS+=getenv.3 setenv.3 getenv.3 unsetenv.3 getenv.3 putenv.3 | 40 | MLINKS+=getenv.3 setenv.3 getenv.3 unsetenv.3 getenv.3 putenv.3 |
| 41 | MLINKS+=malloc.3 free.3 malloc.3 realloc.3 | 41 | MLINKS+=malloc.3 free.3 malloc.3 realloc.3 malloc.3 calloc.3 |
| 42 | MLINKS+=malloc.3 cfree.3 malloc.3 malloc.conf.5 | 42 | MLINKS+=malloc.3 cfree.3 malloc.3 malloc.conf.5 |
| 43 | MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3 | 43 | MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3 |
| 44 | MLINKS+=rand.3 srand.3 | 44 | MLINKS+=rand.3 srand.3 |
diff --git a/src/lib/libc/stdlib/calloc.3 b/src/lib/libc/stdlib/calloc.3 deleted file mode 100644 index 7b78521c4a..0000000000 --- a/src/lib/libc/stdlib/calloc.3 +++ /dev/null | |||
| @@ -1,70 +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 | .\" $OpenBSD: calloc.3,v 1.5 1999/06/29 18:36:19 aaron Exp $ | ||
| 37 | .\" | ||
| 38 | .Dd June 29, 1991 | ||
| 39 | .Dt CALLOC 3 | ||
| 40 | .Os | ||
| 41 | .Sh NAME | ||
| 42 | .Nm calloc | ||
| 43 | .Nd allocate clean memory (zero initialized space) | ||
| 44 | .Sh SYNOPSIS | ||
| 45 | .Fd #include <stdlib.h> | ||
| 46 | .Ft void * | ||
| 47 | .Fn calloc "size_t nmemb" "size_t size" | ||
| 48 | .Sh DESCRIPTION | ||
| 49 | The | ||
| 50 | .Fn calloc | ||
| 51 | function allocates space for an array of | ||
| 52 | .Fa nmemb | ||
| 53 | objects, each of whose size is | ||
| 54 | .Fa size . | ||
| 55 | The space is initialized to all bits zero. | ||
| 56 | .Sh RETURN VALUES | ||
| 57 | The | ||
| 58 | .Fn calloc | ||
| 59 | function returns | ||
| 60 | a pointer to | ||
| 61 | the allocated space if successful; otherwise a null pointer is returned. | ||
| 62 | .Sh SEE ALSO | ||
| 63 | .Xr free 3 , | ||
| 64 | .Xr malloc 3 , | ||
| 65 | .Xr realloc 3 | ||
| 66 | .Sh STANDARDS | ||
| 67 | The | ||
| 68 | .Fn calloc | ||
| 69 | function conforms to | ||
| 70 | .St -ansiC . | ||
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3 index e7c237c63a..c9c87cf420 100644 --- a/src/lib/libc/stdlib/malloc.3 +++ b/src/lib/libc/stdlib/malloc.3 | |||
| @@ -33,31 +33,30 @@ | |||
| 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 | .\" $OpenBSD: malloc.3,v 1.15 1999/06/29 18:36:21 aaron Exp $ | 36 | .\" $OpenBSD: malloc.3,v 1.16 1999/11/09 22:12:36 aaron Exp $ |
| 37 | .\" | 37 | .\" |
| 38 | .Dd August 27, 1996 | 38 | .Dd August 27, 1996 |
| 39 | .Dt MALLOC 3 | 39 | .Dt MALLOC 3 |
| 40 | .Os | 40 | .Os |
| 41 | .Sh NAME | 41 | .Sh NAME |
| 42 | .Nm malloc , | 42 | .Nm malloc , |
| 43 | .Nd general memory allocation function | 43 | .Nm calloc , |
| 44 | .Pp | 44 | .Nm realloc , |
| 45 | .Nm free , | 45 | .Nm free , |
| 46 | .Nm cfree | 46 | .Nm cfree |
| 47 | .Nd free up memory allocated with malloc, calloc or realloc | 47 | .Nd memory allocation and deallocation |
| 48 | .Pp | ||
| 49 | .Nm realloc | ||
| 50 | .Nd reallocation of memory function | ||
| 51 | .Sh SYNOPSIS | 48 | .Sh SYNOPSIS |
| 52 | .Fd #include <stdlib.h> | 49 | .Fd #include <stdlib.h> |
| 53 | .Ft void * | 50 | .Ft void * |
| 54 | .Fn malloc "size_t size" | 51 | .Fn malloc "size_t size" |
| 52 | .Ft void * | ||
| 53 | .Fn calloc "size_t nmemb" "size_t size" | ||
| 54 | .Ft void * | ||
| 55 | .Fn realloc "void *ptr" "size_t size" | ||
| 55 | .Ft void | 56 | .Ft void |
| 56 | .Fn free "void *ptr" | 57 | .Fn free "void *ptr" |
| 57 | .Ft void | 58 | .Ft void |
| 58 | .Fn cfree "void *ptr" | 59 | .Fn cfree "void *ptr" |
| 59 | .Ft void * | ||
| 60 | .Fn realloc "void *ptr" "size_t size" | ||
| 61 | .Ft char * | 60 | .Ft char * |
| 62 | .Va malloc_options | 61 | .Va malloc_options |
| 63 | .Sh DESCRIPTION | 62 | .Sh DESCRIPTION |
| @@ -80,6 +79,14 @@ or larger, the memory returned will be page-aligned. | |||
| 80 | Allocation of a zero size object returns a pointer to a zero size object. | 79 | Allocation of a zero size object returns a pointer to a zero size object. |
| 81 | .Pp | 80 | .Pp |
| 82 | The | 81 | The |
| 82 | .Fn calloc | ||
| 83 | function allocates space for an array of | ||
| 84 | .Fa nmemb | ||
| 85 | objects, each of whose size is | ||
| 86 | .Fa size . | ||
| 87 | The space is initialized to all bits zero. | ||
| 88 | .Pp | ||
| 89 | The | ||
| 83 | .Fn free | 90 | .Fn free |
| 84 | function causes the space pointed to by | 91 | function causes the space pointed to by |
| 85 | .Fa ptr | 92 | .Fa ptr |
| @@ -231,13 +238,17 @@ See above. | |||
| 231 | .Sh RETURN VALUES | 238 | .Sh RETURN VALUES |
| 232 | The | 239 | The |
| 233 | .Fn malloc | 240 | .Fn malloc |
| 234 | function returns | 241 | and |
| 242 | .Fn calloc | ||
| 243 | functions return | ||
| 235 | a pointer to the allocated space if successful; otherwise | 244 | a pointer to the allocated space if successful; otherwise |
| 236 | a null pointer is returned. | 245 | a null pointer is returned. |
| 237 | .Pp | 246 | .Pp |
| 238 | The | 247 | The |
| 239 | .Fn free | 248 | .Fn free |
| 240 | function returns no value. | 249 | and |
| 250 | .Fn cfree | ||
| 251 | functions return no value. | ||
| 241 | .Pp | 252 | .Pp |
| 242 | The | 253 | The |
| 243 | .Fn realloc | 254 | .Fn realloc |
| @@ -286,14 +297,16 @@ A pointer to a free chunk is attempted freed again. | |||
| 286 | .Pp | 297 | .Pp |
| 287 | ``junk pointer, too high to make sense.'' | 298 | ``junk pointer, too high to make sense.'' |
| 288 | The pointer doesn't make sense. It's above the area of memory that | 299 | The pointer doesn't make sense. It's above the area of memory that |
| 289 | malloc knows something about. | 300 | .Fn malloc |
| 301 | knows something about. | ||
| 290 | This could be a pointer from some | 302 | This could be a pointer from some |
| 291 | .Xr mmap 2 'ed | 303 | .Xr mmap 2 'ed |
| 292 | memory. | 304 | memory. |
| 293 | .Pp | 305 | .Pp |
| 294 | ``junk pointer, too low to make sense.'' | 306 | ``junk pointer, too low to make sense.'' |
| 295 | The pointer doesn't make sense. It's below the area of memory that | 307 | The pointer doesn't make sense. It's below the area of memory that |
| 296 | malloc knows something about. | 308 | .Fn malloc |
| 309 | knows something about. | ||
| 297 | This pointer probably came from your data or bss segments. | 310 | This pointer probably came from your data or bss segments. |
| 298 | .Pp | 311 | .Pp |
| 299 | ``malloc() has never been called.'' | 312 | ``malloc() has never been called.'' |
| @@ -304,7 +317,9 @@ realloc'ed. | |||
| 304 | The pointer passed to free or realloc has been modified. | 317 | The pointer passed to free or realloc has been modified. |
| 305 | .Pp | 318 | .Pp |
| 306 | ``pointer to wrong page.'' | 319 | ``pointer to wrong page.'' |
| 307 | The pointer that malloc is trying to free is not pointing to | 320 | The pointer that |
| 321 | .Fn malloc | ||
| 322 | is trying to free is not pointing to | ||
| 308 | a sensible page. | 323 | a sensible page. |
| 309 | .Pp | 324 | .Pp |
| 310 | ``recursive call.'' | 325 | ``recursive call.'' |
| @@ -338,14 +353,20 @@ The | |||
| 338 | function conforms to | 353 | function conforms to |
| 339 | .St -ansiC . | 354 | .St -ansiC . |
| 340 | .Sh HISTORY | 355 | .Sh HISTORY |
| 341 | The present implementation of malloc started out as a filesystem on a drum | 356 | The present implementation of |
| 342 | attached to a 20bit binary challenged computer built with discrete germanium | 357 | .Fn malloc |
| 358 | started out as a filesystem on a drum | ||
| 359 | attached to a 20-bit binary challenged computer built with discrete germanium | ||
| 343 | transistors, and it has since graduated to handle primary storage rather than | 360 | transistors, and it has since graduated to handle primary storage rather than |
| 344 | secondary. | 361 | secondary. |
| 345 | .Pp | 362 | .Pp |
| 346 | The main difference from other malloc implementations are believed to be that | 363 | The main difference from other |
| 364 | .Fn malloc | ||
| 365 | implementations are believed to be that | ||
| 347 | the free pages are not accessed until allocated. | 366 | the free pages are not accessed until allocated. |
| 348 | Most malloc implementations will store a data structure containing a, | 367 | Most |
| 368 | .Fn malloc | ||
| 369 | implementations will store a data structure containing a, | ||
| 349 | possibly double-, linked list in the free chunks of memory, used to tie | 370 | possibly double-, linked list in the free chunks of memory, used to tie |
| 350 | all the free memory together. | 371 | all the free memory together. |
| 351 | That is a quite suboptimal thing to do. | 372 | That is a quite suboptimal thing to do. |
