Browse Source

Merge calloc(3) man page into malloc.3; as suggested by millert@

OPENBSD_2_7
aaron 25 years ago
parent
commit
cdda3b8eef
3 changed files with 41 additions and 90 deletions
  1. +2
    -2
      src/lib/libc/stdlib/Makefile.inc
  2. +0
    -70
      src/lib/libc/stdlib/calloc.3
  3. +39
    -18
      src/lib/libc/stdlib/malloc.3

+ 2
- 2
src/lib/libc/stdlib/Makefile.inc View File

@ -33,12 +33,12 @@ SRCS+= abs.c div.c labs.c ldiv.c
.endif .endif
MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \ 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 \ 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 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+=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+=malloc.3 cfree.3 malloc.3 malloc.conf.5
MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3 MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3
MLINKS+=rand.3 srand.3 MLINKS+=rand.3 srand.3


+ 0
- 70
src/lib/libc/stdlib/calloc.3 View File

@ -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 .

+ 39
- 18
src/lib/libc/stdlib/malloc.3 View File

@ -33,31 +33,30 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" 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 .Dd August 27, 1996
.Dt MALLOC 3 .Dt MALLOC 3
.Os .Os
.Sh NAME .Sh NAME
.Nm malloc , .Nm malloc ,
.Nd general memory allocation function
.Pp
.Nm calloc ,
.Nm realloc ,
.Nm free , .Nm free ,
.Nm cfree .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 .Sh SYNOPSIS
.Fd #include <stdlib.h> .Fd #include <stdlib.h>
.Ft void * .Ft void *
.Fn malloc "size_t size" .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 .Ft void
.Fn free "void *ptr" .Fn free "void *ptr"
.Ft void .Ft void
.Fn cfree "void *ptr" .Fn cfree "void *ptr"
.Ft void *
.Fn realloc "void *ptr" "size_t size"
.Ft char * .Ft char *
.Va malloc_options .Va malloc_options
.Sh DESCRIPTION .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. Allocation of a zero size object returns a pointer to a zero size object.
.Pp .Pp
The 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 .Fn free
function causes the space pointed to by function causes the space pointed to by
.Fa ptr .Fa ptr
@ -231,13 +238,17 @@ See above.
.Sh RETURN VALUES .Sh RETURN VALUES
The The
.Fn malloc .Fn malloc
function returns
and
.Fn calloc
functions return
a pointer to the allocated space if successful; otherwise a pointer to the allocated space if successful; otherwise
a null pointer is returned. a null pointer is returned.
.Pp .Pp
The The
.Fn free .Fn free
function returns no value.
and
.Fn cfree
functions return no value.
.Pp .Pp
The The
.Fn realloc .Fn realloc
@ -286,14 +297,16 @@ A pointer to a free chunk is attempted freed again.
.Pp .Pp
``junk pointer, too high to make sense.'' ``junk pointer, too high to make sense.''
The pointer doesn't make sense. It's above the area of memory that 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 This could be a pointer from some
.Xr mmap 2 'ed .Xr mmap 2 'ed
memory. memory.
.Pp .Pp
``junk pointer, too low to make sense.'' ``junk pointer, too low to make sense.''
The pointer doesn't make sense. It's below the area of memory that 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. This pointer probably came from your data or bss segments.
.Pp .Pp
``malloc() has never been called.'' ``malloc() has never been called.''
@ -304,7 +317,9 @@ realloc'ed.
The pointer passed to free or realloc has been modified. The pointer passed to free or realloc has been modified.
.Pp .Pp
``pointer to wrong page.'' ``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. a sensible page.
.Pp .Pp
``recursive call.'' ``recursive call.''
@ -338,14 +353,20 @@ The
function conforms to function conforms to
.St -ansiC . .St -ansiC .
.Sh HISTORY .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 transistors, and it has since graduated to handle primary storage rather than
secondary. secondary.
.Pp .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. 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 possibly double-, linked list in the free chunks of memory, used to tie
all the free memory together. all the free memory together.
That is a quite suboptimal thing to do. That is a quite suboptimal thing to do.


Loading…
Cancel
Save