summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/mkdtemp.c
diff options
context:
space:
mode:
authormillert <>2024-01-19 19:45:02 +0000
committermillert <>2024-01-19 19:45:02 +0000
commitbe8f1fea763f42a1109f6b1eb3f56ae521cfdec3 (patch)
tree469de603d2d83787131e234cccbf7802f902cf67 /src/lib/libc/stdlib/mkdtemp.c
parent1d17a25a597033d38c420a0a3add7e5e82dd4c02 (diff)
downloadopenbsd-be8f1fea763f42a1109f6b1eb3f56ae521cfdec3.tar.gz
openbsd-be8f1fea763f42a1109f6b1eb3f56ae521cfdec3.tar.bz2
openbsd-be8f1fea763f42a1109f6b1eb3f56ae521cfdec3.zip
Make our mktemp(3) callback-driven and split into multiple files.
Previously, calling any of the mktemp(3) family would pull in lstat(2), open(2) and mkdir(2). Now, only the necessary system calls will be reachable from the binary. OK deraadt@ guenther@
Diffstat (limited to 'src/lib/libc/stdlib/mkdtemp.c')
-rw-r--r--src/lib/libc/stdlib/mkdtemp.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/lib/libc/stdlib/mkdtemp.c b/src/lib/libc/stdlib/mkdtemp.c
new file mode 100644
index 0000000000..c33c3b4e8b
--- /dev/null
+++ b/src/lib/libc/stdlib/mkdtemp.c
@@ -0,0 +1,33 @@
1/* $OpenBSD: mkdtemp.c,v 1.1 2024/01/19 19:45:02 millert Exp $ */
2/*
3 * Copyright (c) 2024 Todd C. Miller
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <sys/stat.h>
19#include <stdlib.h>
20
21static int
22mkdtemp_cb(const char *path, int flags)
23{
24 return mkdir(path, S_IRUSR|S_IWUSR|S_IXUSR);
25}
26
27char *
28mkdtemp(char *path)
29{
30 if (__mktemp4(path, 0, 0, mkdtemp_cb) == 0)
31 return path;
32 return NULL;
33}