]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Hey Emacs! This file is -*- nroff -*- source. |
2 | .\" | |
3 | .\" Copyright (c) 1993 Michael Haardt | |
4 | .\" (michael@moria.de), | |
5 | .\" Fri Apr 2 11:32:09 MET DST 1993 | |
6 | .\" | |
7 | .\" This is free documentation; you can redistribute it and/or | |
8 | .\" modify it under the terms of the GNU General Public License as | |
9 | .\" published by the Free Software Foundation; either version 2 of | |
10 | .\" the License, or (at your option) any later version. | |
11 | .\" | |
12 | .\" The GNU General Public License's references to "object code" | |
13 | .\" and "executables" are to be interpreted as the output of any | |
14 | .\" document formatting or typesetting system, including | |
15 | .\" intermediate and printed output. | |
16 | .\" | |
17 | .\" This manual is distributed in the hope that it will be useful, | |
18 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | .\" GNU General Public License for more details. | |
21 | .\" | |
22 | .\" You should have received a copy of the GNU General Public | |
23 | .\" License along with this manual; if not, write to the Free | |
24 | .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, | |
25 | .\" USA. | |
26 | .\" | |
27 | .\" Modified Wed Jul 21 19:52:58 1993 by Rik Faith <faith@cs.unc.edu> | |
28 | .\" Modified Sun Aug 21 17:40:38 1994 by Rik Faith <faith@cs.unc.edu> | |
29 | .\" | |
30 | .TH BRK 2 2003-11-01 "Linux 2.4" "Linux Programmer's Manual" | |
31 | .SH NAME | |
32 | brk, sbrk \- change data segment size | |
33 | .SH SYNOPSIS | |
34 | .B #include <unistd.h> | |
35 | .sp | |
36 | .BI "int brk(void *" end_data_segment ); | |
37 | .sp | |
38 | .BI "void *sbrk(intptr_t " increment ); | |
39 | .SH DESCRIPTION | |
e511ffb6 | 40 | .BR brk () |
fea681da MK |
41 | sets the end of the data segment to the value specified by |
42 | .IR end_data_segment , | |
43 | when that value is reasonable, the system does have enough memory | |
44 | and the process does not exceed its max data size (see | |
45 | .BR setrlimit (2)). | |
46 | ||
e511ffb6 | 47 | .BR sbrk () |
fea681da MK |
48 | increments the program's data space by |
49 | .I increment | |
50 | bytes. | |
e511ffb6 | 51 | .BR sbrk () |
fea681da MK |
52 | isn't a system call, it is just a C library wrapper. |
53 | Calling | |
e511ffb6 | 54 | .BR sbrk () |
fea681da MK |
55 | with an increment of 0 can be used to find the current |
56 | location of the program break. | |
57 | .SH "RETURN VALUE" | |
58 | On success, | |
e511ffb6 | 59 | .BR brk () |
be352a31 MK |
60 | returns zero. |
61 | On error, \-1 is returned, and | |
62 | .I errno | |
63 | is set to | |
64 | .BR ENOMEM . | |
65 | (But see LINUX NOTES below.) | |
66 | ||
67 | On success, | |
e511ffb6 | 68 | .BR sbrk () |
c13182ef | 69 | returns a pointer to the start of the new area. |
be352a31 | 70 | On error, \-1 is returned, and |
fea681da MK |
71 | .I errno |
72 | is set to | |
73 | .BR ENOMEM . | |
74 | .SH "CONFORMING TO" | |
97c1eac8 | 75 | 4.3BSD; SUSv1, marked LEGACY in SUSv2, removed in POSIX.1-2001. |
fea681da | 76 | |
ae050d9a | 77 | .BR brk () |
c13182ef | 78 | and |
ae050d9a | 79 | .BR sbrk () |
fea681da MK |
80 | are not defined in the C Standard and are deliberately excluded from the |
81 | POSIX.1 standard (see paragraphs B.1.1.1.3 and B.8.3.3). | |
82 | .SH NOTES | |
83 | Various systems use various types for the parameter of | |
84 | .BR sbrk (). | |
9ff08aad | 85 | Common are \fIint\fP, \fIssize_t\fP, \fIptrdiff_t\fP, \fIintptr_t\fP. |
fea681da | 86 | .\" One sees |
9ff08aad MK |
87 | .\" \fIint\fP (e.g. XPGv4, DU 4.0, HP-UX 11, FreeBSD 4.0, OpenBSD 3.2), |
88 | .\" \fIssize_t\fP (OSF1 2.0, Irix 5.3, 6.5), | |
89 | .\" \fIptrdiff_t\fP (libc4, libc5, ulibc, glibc2.0, 2.1), | |
90 | .\" \fIintptr_t\fP (e.g. XPGv5, AIX, SunOS 5.8, 5.9, FreeBSD 4.7, NetBSD 1.6, | |
fea681da | 91 | .\" Tru64 5.1, glibc2.2). |
be352a31 MK |
92 | .SH LINUX NOTES |
93 | The return value described above for | |
94 | .BR brk () | |
95 | is the behaviour provided by the glibc wrapper function for the Linux | |
96 | .BR brk () | |
c13182ef MK |
97 | system call. |
98 | (On most other implementations, the return value from | |
99 | .BR brk () | |
be352a31 | 100 | is the same.) |
c13182ef | 101 | However, |
be352a31 | 102 | the actual Linux system call returns the new program break on success. |
c13182ef | 103 | On failure, the system call returns the current break |
be352a31 MK |
104 | (thus for example, the call |
105 | .I brk(0) | |
106 | can be used to obtain the current break). | |
c13182ef | 107 | The glibc wrapper function does some work to provide the 0 |
be352a31 MK |
108 | and \-1 return values described above. |
109 | ||
c13182ef | 110 | On Linux, |
be352a31 MK |
111 | .BR sbrk () |
112 | is implemented as a library function that uses the | |
113 | .BR brk () | |
c13182ef | 114 | system call, and does some internal bookkeeping so that it can |
be352a31 | 115 | return the old break value. |
fea681da MK |
116 | .SH "SEE ALSO" |
117 | .BR execve (2), | |
118 | .BR getrlimit (2), | |
119 | .BR malloc (3) |