summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoraaron <>1999-11-09 22:12:36 +0000
committeraaron <>1999-11-09 22:12:36 +0000
commit804f568be8b94c5d121b519265452c56bd2efb50 (patch)
tree8e8983be58be19c795441fe752c4a3b616216b09 /src
parent5d55745080b705a4223d109d1dbbd95cf1072a73 (diff)
downloadopenbsd-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')
-rw-r--r--src/lib/libc/stdlib/Makefile.inc4
-rw-r--r--src/lib/libc/stdlib/calloc.370
-rw-r--r--src/lib/libc/stdlib/malloc.357
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
35MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \ 35MAN+= 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
40MLINKS+=getenv.3 setenv.3 getenv.3 unsetenv.3 getenv.3 putenv.3 40MLINKS+=getenv.3 setenv.3 getenv.3 unsetenv.3 getenv.3 putenv.3
41MLINKS+=malloc.3 free.3 malloc.3 realloc.3 41MLINKS+=malloc.3 free.3 malloc.3 realloc.3 malloc.3 calloc.3
42MLINKS+=malloc.3 cfree.3 malloc.3 malloc.conf.5 42MLINKS+=malloc.3 cfree.3 malloc.3 malloc.conf.5
43MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3 43MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3
44MLINKS+=rand.3 srand.3 44MLINKS+=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
49The
50.Fn calloc
51function allocates space for an array of
52.Fa nmemb
53objects, each of whose size is
54.Fa size .
55The space is initialized to all bits zero.
56.Sh RETURN VALUES
57The
58.Fn calloc
59function returns
60a pointer to
61the 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
67The
68.Fn calloc
69function 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.
80Allocation of a zero size object returns a pointer to a zero size object. 79Allocation of a zero size object returns a pointer to a zero size object.
81.Pp 80.Pp
82The 81The
82.Fn calloc
83function allocates space for an array of
84.Fa nmemb
85objects, each of whose size is
86.Fa size .
87The space is initialized to all bits zero.
88.Pp
89The
83.Fn free 90.Fn free
84function causes the space pointed to by 91function 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
232The 239The
233.Fn malloc 240.Fn malloc
234function returns 241and
242.Fn calloc
243functions return
235a pointer to the allocated space if successful; otherwise 244a pointer to the allocated space if successful; otherwise
236a null pointer is returned. 245a null pointer is returned.
237.Pp 246.Pp
238The 247The
239.Fn free 248.Fn free
240function returns no value. 249and
250.Fn cfree
251functions return no value.
241.Pp 252.Pp
242The 253The
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.''
288The pointer doesn't make sense. It's above the area of memory that 299The pointer doesn't make sense. It's above the area of memory that
289malloc knows something about. 300.Fn malloc
301knows something about.
290This could be a pointer from some 302This could be a pointer from some
291.Xr mmap 2 'ed 303.Xr mmap 2 'ed
292memory. 304memory.
293.Pp 305.Pp
294``junk pointer, too low to make sense.'' 306``junk pointer, too low to make sense.''
295The pointer doesn't make sense. It's below the area of memory that 307The pointer doesn't make sense. It's below the area of memory that
296malloc knows something about. 308.Fn malloc
309knows something about.
297This pointer probably came from your data or bss segments. 310This 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.
304The pointer passed to free or realloc has been modified. 317The pointer passed to free or realloc has been modified.
305.Pp 318.Pp
306``pointer to wrong page.'' 319``pointer to wrong page.''
307The pointer that malloc is trying to free is not pointing to 320The pointer that
321.Fn malloc
322is trying to free is not pointing to
308a sensible page. 323a sensible page.
309.Pp 324.Pp
310``recursive call.'' 325``recursive call.''
@@ -338,14 +353,20 @@ The
338function conforms to 353function conforms to
339.St -ansiC . 354.St -ansiC .
340.Sh HISTORY 355.Sh HISTORY
341The present implementation of malloc started out as a filesystem on a drum 356The present implementation of
342attached to a 20bit binary challenged computer built with discrete germanium 357.Fn malloc
358started out as a filesystem on a drum
359attached to a 20-bit binary challenged computer built with discrete germanium
343transistors, and it has since graduated to handle primary storage rather than 360transistors, and it has since graduated to handle primary storage rather than
344secondary. 361secondary.
345.Pp 362.Pp
346The main difference from other malloc implementations are believed to be that 363The main difference from other
364.Fn malloc
365implementations are believed to be that
347the free pages are not accessed until allocated. 366the free pages are not accessed until allocated.
348Most malloc implementations will store a data structure containing a, 367Most
368.Fn malloc
369implementations will store a data structure containing a,
349possibly double-, linked list in the free chunks of memory, used to tie 370possibly double-, linked list in the free chunks of memory, used to tie
350all the free memory together. 371all the free memory together.
351That is a quite suboptimal thing to do. 372That is a quite suboptimal thing to do.