summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/stdlib')
-rw-r--r--src/lib/libc/stdlib/exit.311
-rw-r--r--src/lib/libc/stdlib/malloc.328
-rw-r--r--src/lib/libc/stdlib/malloc.c9
-rw-r--r--src/lib/libc/stdlib/mkstemp.c5
-rw-r--r--src/lib/libc/stdlib/mktemp.342
-rw-r--r--src/lib/libc/stdlib/ptsname.36
-rw-r--r--src/lib/libc/stdlib/rand48.38
-rw-r--r--src/lib/libc/stdlib/realpath.36
8 files changed, 58 insertions, 57 deletions
diff --git a/src/lib/libc/stdlib/exit.3 b/src/lib/libc/stdlib/exit.3
index 22acade86c..ccb416ee82 100644
--- a/src/lib/libc/stdlib/exit.3
+++ b/src/lib/libc/stdlib/exit.3
@@ -29,9 +29,9 @@
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE. 30.\" SUCH DAMAGE.
31.\" 31.\"
32.\" $OpenBSD: exit.3,v 1.18 2024/08/30 03:44:48 guenther Exp $ 32.\" $OpenBSD: exit.3,v 1.19 2025/06/03 14:15:53 yasuoka Exp $
33.\" 33.\"
34.Dd $Mdocdate: August 30 2024 $ 34.Dd $Mdocdate: June 3 2025 $
35.Dt EXIT 3 35.Dt EXIT 3
36.Os 36.Os
37.Sh NAME 37.Sh NAME
@@ -54,9 +54,7 @@ Call the functions registered with the
54.Xr atexit 3 54.Xr atexit 3
55function, in the reverse order of their registration. 55function, in the reverse order of their registration.
56.It 56.It
57Flush all open output streams. 57Flush and close all open streams.
58.It
59Close all open streams.
60.It 58.It
61Unlink all files created with the 59Unlink all files created with the
62.Xr tmpfile 3 60.Xr tmpfile 3
@@ -79,6 +77,7 @@ function never returns.
79.Sh SEE ALSO 77.Sh SEE ALSO
80.Xr _exit 2 , 78.Xr _exit 2 ,
81.Xr atexit 3 , 79.Xr atexit 3 ,
80.Xr fflush 3 ,
82.Xr intro 3 , 81.Xr intro 3 ,
83.Xr sysexits 3 , 82.Xr sysexits 3 ,
84.Xr tmpfile 3 83.Xr tmpfile 3
@@ -86,7 +85,7 @@ function never returns.
86The 85The
87.Fn exit 86.Fn exit
88function conforms to 87function conforms to
89.St -isoC-99 . 88.St -p1003.1-2024 .
90.Sh HISTORY 89.Sh HISTORY
91An 90An
92.Fn exit 91.Fn exit
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3
index bea5575bf8..ee13b01bd4 100644
--- a/src/lib/libc/stdlib/malloc.3
+++ b/src/lib/libc/stdlib/malloc.3
@@ -30,9 +30,9 @@
30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE. 31.\" SUCH DAMAGE.
32.\" 32.\"
33.\" $OpenBSD: malloc.3,v 1.142 2024/08/03 20:09:24 guenther Exp $ 33.\" $OpenBSD: malloc.3,v 1.147 2025/06/04 00:38:01 yasuoka Exp $
34.\" 34.\"
35.Dd $Mdocdate: August 3 2024 $ 35.Dd $Mdocdate: June 4 2025 $
36.Dt MALLOC 3 36.Dt MALLOC 3
37.Os 37.Os
38.Sh NAME 38.Sh NAME
@@ -69,7 +69,8 @@
69.Fn malloc_conceal "size_t size" 69.Fn malloc_conceal "size_t size"
70.Ft void * 70.Ft void *
71.Fn calloc_conceal "size_t nmemb" "size_t size" 71.Fn calloc_conceal "size_t nmemb" "size_t size"
72.Vt char *malloc_options ; 72.Vt const char * const
73.Va malloc_options ;
73.Sh DESCRIPTION 74.Sh DESCRIPTION
74The standard functions 75The standard functions
75.Fn malloc , 76.Fn malloc ,
@@ -268,7 +269,15 @@ next checks the environment for a variable called
268and finally looks at the global variable 269and finally looks at the global variable
269.Va malloc_options 270.Va malloc_options
270in the program. 271in the program.
271Each is scanned for the flags documented below. 272Since
273.Fn malloc
274might already get called before the beginning of
275.Fn main ,
276either initialize
277.Va malloc_options
278to a string literal at file scope or do not declare it at all.
279.Pp
280Each of the three strings is scanned for the flags documented below.
272Unless otherwise noted uppercase means on, lowercase means off. 281Unless otherwise noted uppercase means on, lowercase means off.
273During initialization, flags occurring later modify the behaviour 282During initialization, flags occurring later modify the behaviour
274that was requested by flags processed earlier. 283that was requested by flags processed earlier.
@@ -363,18 +372,9 @@ Use with
363to get a verbose dump of malloc's internal state. 372to get a verbose dump of malloc's internal state.
364.It Cm X 373.It Cm X
365.Dq xmalloc . 374.Dq xmalloc .
366Rather than return failure, 375Rather than return failure to handle out-of-memory conditions gracefully,
367.Xr abort 3 376.Xr abort 3
368the program with a diagnostic message on stderr. 377the program with a diagnostic message on stderr.
369It is the intention that this option be set at compile time by
370including in the source:
371.Bd -literal -offset indent
372extern char *malloc_options;
373malloc_options = "X";
374.Ed
375.Pp
376Note that this will cause code that is supposed to handle
377out-of-memory conditions gracefully to abort instead.
378.It Cm < 378.It Cm <
379.Dq Halve the cache size . 379.Dq Halve the cache size .
380Decrease the size of the free page cache by a factor of two. 380Decrease the size of the free page cache by a factor of two.
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c
index cad8e5d6a1..c6261d87c5 100644
--- a/src/lib/libc/stdlib/malloc.c
+++ b/src/lib/libc/stdlib/malloc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: malloc.c,v 1.297 2024/09/20 02:00:46 jsg Exp $ */ 1/* $OpenBSD: malloc.c,v 1.299 2025/06/12 16:07:09 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2008, 2010, 2011, 2016, 2023 Otto Moerbeek <otto@drijf.net> 3 * Copyright (c) 2008, 2010, 2011, 2016, 2023 Otto Moerbeek <otto@drijf.net>
4 * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> 4 * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org>
@@ -31,7 +31,6 @@
31#include <sys/queue.h> 31#include <sys/queue.h>
32#include <sys/mman.h> 32#include <sys/mman.h>
33#include <sys/sysctl.h> 33#include <sys/sysctl.h>
34#include <uvm/uvmexp.h>
35#include <errno.h> 34#include <errno.h>
36#include <stdarg.h> 35#include <stdarg.h>
37#include <stdint.h> 36#include <stdint.h>
@@ -264,7 +263,8 @@ static union {
264 __attribute__((section(".openbsd.mutable"))); 263 __attribute__((section(".openbsd.mutable")));
265#define mopts malloc_readonly.mopts 264#define mopts malloc_readonly.mopts
266 265
267char *malloc_options; /* compile-time options */ 266/* compile-time options */
267const char *const malloc_options __attribute__((weak));
268 268
269static __dead void wrterror(struct dir_info *d, char *msg, ...) 269static __dead void wrterror(struct dir_info *d, char *msg, ...)
270 __attribute__((__format__ (printf, 2, 3))); 270 __attribute__((__format__ (printf, 2, 3)));
@@ -501,7 +501,8 @@ omalloc_parseopt(char opt)
501static void 501static void
502omalloc_init(void) 502omalloc_init(void)
503{ 503{
504 char *p, *q, b[16]; 504 const char *p;
505 char *q, b[16];
505 int i, j; 506 int i, j;
506 const int mib[2] = { CTL_VM, VM_MALLOC_CONF }; 507 const int mib[2] = { CTL_VM, VM_MALLOC_CONF };
507 size_t sb; 508 size_t sb;
diff --git a/src/lib/libc/stdlib/mkstemp.c b/src/lib/libc/stdlib/mkstemp.c
index 75a9d27d1a..760575005f 100644
--- a/src/lib/libc/stdlib/mkstemp.c
+++ b/src/lib/libc/stdlib/mkstemp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: mkstemp.c,v 1.1 2024/01/19 19:45:02 millert Exp $ */ 1/* $OpenBSD: mkstemp.c,v 1.2 2025/08/04 04:59:31 guenther Exp $ */
2/* 2/*
3 * Copyright (c) 2024 Todd C. Miller 3 * Copyright (c) 2024 Todd C. Miller
4 * 4 *
@@ -20,7 +20,8 @@
20#include <fcntl.h> 20#include <fcntl.h>
21#include <stdlib.h> 21#include <stdlib.h>
22 22
23#define MKOSTEMP_FLAGS (O_APPEND | O_CLOEXEC | O_DSYNC | O_RSYNC | O_SYNC) 23#define MKOSTEMP_FLAGS \
24 (O_APPEND | O_CLOEXEC | O_CLOFORK | O_DSYNC | O_RSYNC | O_SYNC)
24 25
25static int 26static int
26mkstemp_cb(const char *path, int flags) 27mkstemp_cb(const char *path, int flags)
diff --git a/src/lib/libc/stdlib/mktemp.3 b/src/lib/libc/stdlib/mktemp.3
index 83b7c9eb30..a967358164 100644
--- a/src/lib/libc/stdlib/mktemp.3
+++ b/src/lib/libc/stdlib/mktemp.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: mktemp.3,v 1.2 2024/03/01 21:30:40 millert Exp $ 1.\" $OpenBSD: mktemp.3,v 1.4 2025/08/04 14:11:37 schwarze Exp $
2.\" 2.\"
3.\" Copyright (c) 1989, 1991, 1993 3.\" Copyright (c) 1989, 1991, 1993
4.\" The Regents of the University of California. All rights reserved. 4.\" The Regents of the University of California. All rights reserved.
@@ -27,17 +27,17 @@
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE. 28.\" SUCH DAMAGE.
29.\" 29.\"
30.Dd $Mdocdate: March 1 2024 $ 30.Dd $Mdocdate: August 4 2025 $
31.Dt MKTEMP 3 31.Dt MKTEMP 3
32.Os 32.Os
33.Sh NAME 33.Sh NAME
34.Nm mktemp , 34.Nm mktemp ,
35.Nm mkstemp , 35.Nm mkstemp ,
36.Nm mkostemp ,
37.Nm mkstemps , 36.Nm mkstemps ,
38.Nm mkostemps ,
39.Nm mkdtemp , 37.Nm mkdtemp ,
40.Nm mkdtemps 38.Nm mkdtemps ,
39.Nm mkostemp ,
40.Nm mkostemps
41.Nd make temporary file name (unique) 41.Nd make temporary file name (unique)
42.Sh SYNOPSIS 42.Sh SYNOPSIS
43.In stdlib.h 43.In stdlib.h
@@ -119,6 +119,8 @@ system call:
119Append on each write. 119Append on each write.
120.It Dv O_CLOEXEC 120.It Dv O_CLOEXEC
121Set the close-on-exec flag on the new file descriptor. 121Set the close-on-exec flag on the new file descriptor.
122.It Dv O_CLOFORK
123Set the close-on-fork flag on the new file descriptor.
122.It Dv O_SYNC 124.It Dv O_SYNC
123Perform synchronous I/O operations. 125Perform synchronous I/O operations.
124.El 126.El
@@ -163,8 +165,8 @@ functions return a pointer to the template on success and
163on failure. 165on failure.
164The 166The
165.Fn mkstemp , 167.Fn mkstemp ,
166.Fn mkostemp ,
167.Fn mkstemps , 168.Fn mkstemps ,
169.Fn mkostemp ,
168and 170and
169.Fn mkostemps 171.Fn mkostemps
170functions return \-1 if no suitable file could be created. 172functions return \-1 if no suitable file could be created.
@@ -253,9 +255,9 @@ of
253The 255The
254.Fn mktemp , 256.Fn mktemp ,
255.Fn mkstemp , 257.Fn mkstemp ,
256.Fn mkostemp , 258.Fn mkdtemp ,
257and 259and
258.Fn mkdtemp 260.Fn mkostemp
259functions may set 261functions may set
260.Va errno 262.Va errno
261to one of the following values: 263to one of the following values:
@@ -318,8 +320,8 @@ function.
318.Pp 320.Pp
319The 321The
320.Fn mkstemp , 322.Fn mkstemp ,
321.Fn mkostemp ,
322.Fn mkstemps , 323.Fn mkstemps ,
324.Fn mkostemp ,
323and 325and
324.Fn mkostemps 326.Fn mkostemps
325functions may also set 327functions may also set
@@ -345,18 +347,16 @@ function.
345.Xr tmpnam 3 347.Xr tmpnam 3
346.Sh STANDARDS 348.Sh STANDARDS
347The 349The
348.Fn mkdtemp 350.Fn mkstemp ,
351.Fn mkdtemp ,
349and 352and
350.Fn mkstemp 353.Fn mkostemp
351functions conform to the 354functions conform to the
352.St -p1003.1-2008 355.St -p1003.1-2024
353specification. 356specification.
354The ability to specify more than six 357The ability to specify more than six
355.Em X Ns s 358.Em X Ns s
356is an extension to that standard. 359is an extension to that standard.
357The
358.Fn mkostemp
359function is expected to conform to a future revision of that standard.
360.Pp 360.Pp
361The 361The
362.Fn mktemp 362.Fn mktemp
@@ -368,9 +368,9 @@ it is no longer a part of the standard.
368.Pp 368.Pp
369The 369The
370.Fn mkstemps , 370.Fn mkstemps ,
371.Fn mkostemps , 371.Fn mkdtemps ,
372and 372and
373.Fn mkdtemps 373.Fn mkostemps
374functions are non-standard and should not be used if portability is required. 374functions are non-standard and should not be used if portability is required.
375.Sh HISTORY 375.Sh HISTORY
376A 376A
@@ -378,14 +378,14 @@ A
378function appeared in 378function appeared in
379.At v7 . 379.At v7 .
380The 380The
381.Fn mkdtemp
382function appeared in
383.Ox 2.2 .
384The
385.Fn mkstemp 381.Fn mkstemp
386function appeared in 382function appeared in
387.Bx 4.3 . 383.Bx 4.3 .
388The 384The
385.Fn mkdtemp
386function appeared in
387.Ox 2.2 .
388The
389.Fn mkstemps 389.Fn mkstemps
390function appeared in 390function appeared in
391.Ox 2.3 . 391.Ox 2.3 .
diff --git a/src/lib/libc/stdlib/ptsname.3 b/src/lib/libc/stdlib/ptsname.3
index 98705528f5..eea36a5a02 100644
--- a/src/lib/libc/stdlib/ptsname.3
+++ b/src/lib/libc/stdlib/ptsname.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: ptsname.3,v 1.2 2012/12/04 18:42:16 millert Exp $ 1.\" $OpenBSD: ptsname.3,v 1.3 2025/06/13 18:34:00 schwarze Exp $
2.\" 2.\"
3.\" Copyright (c) 2002 The FreeBSD Project, Inc. 3.\" Copyright (c) 2002 The FreeBSD Project, Inc.
4.\" All rights reserved. 4.\" All rights reserved.
@@ -32,7 +32,7 @@
32.\" 32.\"
33.\" $FreeBSD: head/lib/libc/stdlib/ptsname.3 240412 2012-09-12 17:54:09Z emaste $ 33.\" $FreeBSD: head/lib/libc/stdlib/ptsname.3 240412 2012-09-12 17:54:09Z emaste $
34.\" 34.\"
35.Dd $Mdocdate: December 4 2012 $ 35.Dd $Mdocdate: June 13 2025 $
36.Dt PTSNAME 3 36.Dt PTSNAME 3
37.Os 37.Os
38.Sh NAME 38.Sh NAME
@@ -44,7 +44,7 @@
44.In stdlib.h 44.In stdlib.h
45.Ft int 45.Ft int
46.Fn grantpt "int fildes" 46.Fn grantpt "int fildes"
47.Ft "char *" 47.Ft char *
48.Fn ptsname "int fildes" 48.Fn ptsname "int fildes"
49.Ft int 49.Ft int
50.Fn unlockpt "int fildes" 50.Fn unlockpt "int fildes"
diff --git a/src/lib/libc/stdlib/rand48.3 b/src/lib/libc/stdlib/rand48.3
index fa7a7179bc..02e1999db9 100644
--- a/src/lib/libc/stdlib/rand48.3
+++ b/src/lib/libc/stdlib/rand48.3
@@ -9,9 +9,9 @@
9.\" of any kind. I shall in no event be liable for anything that happens 9.\" of any kind. I shall in no event be liable for anything that happens
10.\" to anyone/anything when using this software. 10.\" to anyone/anything when using this software.
11.\" 11.\"
12.\" $OpenBSD: rand48.3,v 1.21 2019/12/20 19:16:40 tb Exp $ 12.\" $OpenBSD: rand48.3,v 1.22 2025/06/13 18:34:00 schwarze Exp $
13.\" 13.\"
14.Dd $Mdocdate: December 20 2019 $ 14.Dd $Mdocdate: June 13 2025 $
15.Dt DRAND48 3 15.Dt DRAND48 3
16.Os 16.Os
17.Sh NAME 17.Sh NAME
@@ -46,9 +46,9 @@
46.Fn srand48 "long seed" 46.Fn srand48 "long seed"
47.Ft void 47.Ft void
48.Fn srand48_deterministic "long seed" 48.Fn srand48_deterministic "long seed"
49.Ft "unsigned short *" 49.Ft unsigned short *
50.Fn seed48 "unsigned short xseed[3]" 50.Fn seed48 "unsigned short xseed[3]"
51.Ft "unsigned short *" 51.Ft unsigned short *
52.Fn seed48_deterministic "unsigned short xseed[3]" 52.Fn seed48_deterministic "unsigned short xseed[3]"
53.Ft void 53.Ft void
54.Fn lcong48 "unsigned short p[7]" 54.Fn lcong48 "unsigned short p[7]"
diff --git a/src/lib/libc/stdlib/realpath.3 b/src/lib/libc/stdlib/realpath.3
index 1dec10fef4..1f932e3bb5 100644
--- a/src/lib/libc/stdlib/realpath.3
+++ b/src/lib/libc/stdlib/realpath.3
@@ -28,9 +28,9 @@
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE. 29.\" SUCH DAMAGE.
30.\" 30.\"
31.\" $OpenBSD: realpath.3,v 1.26 2021/10/13 15:04:53 kn Exp $ 31.\" $OpenBSD: realpath.3,v 1.27 2025/06/13 18:34:00 schwarze Exp $
32.\" 32.\"
33.Dd $Mdocdate: October 13 2021 $ 33.Dd $Mdocdate: June 13 2025 $
34.Dt REALPATH 3 34.Dt REALPATH 3
35.Os 35.Os
36.Sh NAME 36.Sh NAME
@@ -39,7 +39,7 @@
39.Sh SYNOPSIS 39.Sh SYNOPSIS
40.In limits.h 40.In limits.h
41.In stdlib.h 41.In stdlib.h
42.Ft "char *" 42.Ft char *
43.Fn realpath "const char *pathname" "char *resolved" 43.Fn realpath "const char *pathname" "char *resolved"
44.Sh DESCRIPTION 44.Sh DESCRIPTION
45The 45The