diff options
author | Aaron Campbell <aaron@cvs.openbsd.org> | 1999-11-09 22:12:37 +0000 |
---|---|---|
committer | Aaron Campbell <aaron@cvs.openbsd.org> | 1999-11-09 22:12:37 +0000 |
commit | 70ff420ae569289467e9bc23697c70297d368fce (patch) | |
tree | 7361ac419090ae22c0d26332c1055ed46764865c /lib/libc/stdlib | |
parent | c481629017a269df09c3ec95fc88edb5bdb85d04 (diff) |
Merge calloc(3) man page into malloc.3; as suggested by millert@
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r-- | lib/libc/stdlib/Makefile.inc | 4 | ||||
-rw-r--r-- | lib/libc/stdlib/calloc.3 | 70 | ||||
-rw-r--r-- | lib/libc/stdlib/malloc.3 | 57 |
3 files changed, 41 insertions, 90 deletions
diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc index b1c20d08cd8..9765082276c 100644 --- a/lib/libc/stdlib/Makefile.inc +++ b/lib/libc/stdlib/Makefile.inc @@ -33,12 +33,12 @@ SRCS+= abs.c div.c labs.c ldiv.c .endif MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \ - calloc.3 div.3 exit.3 getenv.3 getopt.3 getsubopt.3 labs.3 ldiv.3 \ + div.3 exit.3 getenv.3 getopt.3 getsubopt.3 labs.3 ldiv.3 \ malloc.3 memory.3 qabs.3 qdiv.3 qsort.3 radixsort.3 rand48.3 rand.3 \ random.3 realpath.3 strtod.3 strtol.3 strtoul.3 system.3 tsearch.3 MLINKS+=getenv.3 setenv.3 getenv.3 unsetenv.3 getenv.3 putenv.3 -MLINKS+=malloc.3 free.3 malloc.3 realloc.3 +MLINKS+=malloc.3 free.3 malloc.3 realloc.3 malloc.3 calloc.3 MLINKS+=malloc.3 cfree.3 malloc.3 malloc.conf.5 MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3 MLINKS+=rand.3 srand.3 diff --git a/lib/libc/stdlib/calloc.3 b/lib/libc/stdlib/calloc.3 deleted file mode 100644 index 7b78521c4a1..00000000000 --- a/lib/libc/stdlib/calloc.3 +++ /dev/null @@ -1,70 +0,0 @@ -.\" Copyright (c) 1991 The Regents of the University of California. -.\" All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" the American National Standards Committee X3, on Information -.\" Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $OpenBSD: calloc.3,v 1.5 1999/06/29 18:36:19 aaron Exp $ -.\" -.Dd June 29, 1991 -.Dt CALLOC 3 -.Os -.Sh NAME -.Nm calloc -.Nd allocate clean memory (zero initialized space) -.Sh SYNOPSIS -.Fd #include <stdlib.h> -.Ft void * -.Fn calloc "size_t nmemb" "size_t size" -.Sh DESCRIPTION -The -.Fn calloc -function allocates space for an array of -.Fa nmemb -objects, each of whose size is -.Fa size . -The space is initialized to all bits zero. -.Sh RETURN VALUES -The -.Fn calloc -function returns -a pointer to -the allocated space if successful; otherwise a null pointer is returned. -.Sh SEE ALSO -.Xr free 3 , -.Xr malloc 3 , -.Xr realloc 3 -.Sh STANDARDS -The -.Fn calloc -function conforms to -.St -ansiC . diff --git a/lib/libc/stdlib/malloc.3 b/lib/libc/stdlib/malloc.3 index e7c237c63a2..c9c87cf4206 100644 --- a/lib/libc/stdlib/malloc.3 +++ b/lib/libc/stdlib/malloc.3 @@ -33,31 +33,30 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: malloc.3,v 1.15 1999/06/29 18:36:21 aaron Exp $ +.\" $OpenBSD: malloc.3,v 1.16 1999/11/09 22:12:36 aaron Exp $ .\" .Dd August 27, 1996 .Dt MALLOC 3 .Os .Sh NAME .Nm malloc , -.Nd general memory allocation function -.Pp +.Nm calloc , +.Nm realloc , .Nm free , .Nm cfree -.Nd free up memory allocated with malloc, calloc or realloc -.Pp -.Nm realloc -.Nd reallocation of memory function +.Nd memory allocation and deallocation .Sh SYNOPSIS .Fd #include <stdlib.h> .Ft void * .Fn malloc "size_t size" +.Ft void * +.Fn calloc "size_t nmemb" "size_t size" +.Ft void * +.Fn realloc "void *ptr" "size_t size" .Ft void .Fn free "void *ptr" .Ft void .Fn cfree "void *ptr" -.Ft void * -.Fn realloc "void *ptr" "size_t size" .Ft char * .Va malloc_options .Sh DESCRIPTION @@ -80,6 +79,14 @@ or larger, the memory returned will be page-aligned. Allocation of a zero size object returns a pointer to a zero size object. .Pp The +.Fn calloc +function allocates space for an array of +.Fa nmemb +objects, each of whose size is +.Fa size . +The space is initialized to all bits zero. +.Pp +The .Fn free function causes the space pointed to by .Fa ptr @@ -231,13 +238,17 @@ See above. .Sh RETURN VALUES The .Fn malloc -function returns +and +.Fn calloc +functions return a pointer to the allocated space if successful; otherwise a null pointer is returned. .Pp The .Fn free -function returns no value. +and +.Fn cfree +functions return no value. .Pp The .Fn realloc @@ -286,14 +297,16 @@ A pointer to a free chunk is attempted freed again. .Pp ``junk pointer, too high to make sense.'' The pointer doesn't make sense. It's above the area of memory that -malloc knows something about. +.Fn malloc +knows something about. This could be a pointer from some .Xr mmap 2 'ed memory. .Pp ``junk pointer, too low to make sense.'' The pointer doesn't make sense. It's below the area of memory that -malloc knows something about. +.Fn malloc +knows something about. This pointer probably came from your data or bss segments. .Pp ``malloc() has never been called.'' @@ -304,7 +317,9 @@ realloc'ed. The pointer passed to free or realloc has been modified. .Pp ``pointer to wrong page.'' -The pointer that malloc is trying to free is not pointing to +The pointer that +.Fn malloc +is trying to free is not pointing to a sensible page. .Pp ``recursive call.'' @@ -338,14 +353,20 @@ The function conforms to .St -ansiC . .Sh HISTORY -The present implementation of malloc started out as a filesystem on a drum -attached to a 20bit binary challenged computer built with discrete germanium +The present implementation of +.Fn malloc +started out as a filesystem on a drum +attached to a 20-bit binary challenged computer built with discrete germanium transistors, and it has since graduated to handle primary storage rather than secondary. .Pp -The main difference from other malloc implementations are believed to be that +The main difference from other +.Fn malloc +implementations are believed to be that the free pages are not accessed until allocated. -Most malloc implementations will store a data structure containing a, +Most +.Fn malloc +implementations will store a data structure containing a, possibly double-, linked list in the free chunks of memory, used to tie all the free memory together. That is a quite suboptimal thing to do. |