From 00c9df314d126a5ad9b4c7debf8ca32c053a7afb Mon Sep 17 00:00:00 2001 From: millert <> Date: Fri, 1 Mar 2024 21:30:40 +0000 Subject: Add mkdtemps(3), like mkdtemp(3) but with a suffix. OK deraadt@ tb@ --- src/lib/libc/stdlib/mkdtemp.c | 10 +++++++++- src/lib/libc/stdlib/mktemp.3 | 30 +++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 8 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libc/stdlib/mkdtemp.c b/src/lib/libc/stdlib/mkdtemp.c index c33c3b4e8b..c11501f893 100644 --- a/src/lib/libc/stdlib/mkdtemp.c +++ b/src/lib/libc/stdlib/mkdtemp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkdtemp.c,v 1.1 2024/01/19 19:45:02 millert Exp $ */ +/* $OpenBSD: mkdtemp.c,v 1.2 2024/03/01 21:30:40 millert Exp $ */ /* * Copyright (c) 2024 Todd C. Miller * @@ -31,3 +31,11 @@ mkdtemp(char *path) return path; return NULL; } + +char * +mkdtemps(char *path, int slen) +{ + if (__mktemp4(path, slen, 0, mkdtemp_cb) == 0) + return path; + return NULL; +} diff --git a/src/lib/libc/stdlib/mktemp.3 b/src/lib/libc/stdlib/mktemp.3 index d4bd7bdc91..83b7c9eb30 100644 --- a/src/lib/libc/stdlib/mktemp.3 +++ b/src/lib/libc/stdlib/mktemp.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: mktemp.3,v 1.1 2024/01/19 16:30:28 millert Exp $ +.\" $OpenBSD: mktemp.3,v 1.2 2024/03/01 21:30:40 millert Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: January 19 2024 $ +.Dd $Mdocdate: March 1 2024 $ .Dt MKTEMP 3 .Os .Sh NAME @@ -36,7 +36,8 @@ .Nm mkostemp , .Nm mkstemps , .Nm mkostemps , -.Nm mkdtemp +.Nm mkdtemp , +.Nm mkdtemps .Nd make temporary file name (unique) .Sh SYNOPSIS .In stdlib.h @@ -48,6 +49,8 @@ .Fn mkstemps "char *template" "int suffixlen" .Ft char * .Fn mkdtemp "char *template" +.Ft char * +.Fn mkdtemps "char *template" "int suffixlen" .In stdlib.h .In fcntl.h .Ft int @@ -142,11 +145,19 @@ The function makes the same replacement to the template as in .Fn mktemp and creates the template directory, mode 0700. +The +.Fn mkdtemps +function acts the same as +.Fn mkdtemp , +except that it permits a suffix to exist in the template, +similar to +.Fn mkstemps . .Sh RETURN VALUES The -.Fn mktemp +.Fn mktemp , +.Fn mkdtemp , and -.Fn mkdtemp +.Fn mkdtemps functions return a pointer to the template on success and .Dv NULL on failure. @@ -356,9 +367,10 @@ as of it is no longer a part of the standard. .Pp The -.Fn mkstemps +.Fn mkstemps , +.Fn mkostemps , and -.Fn mkostemps +.Fn mkdtemps functions are non-standard and should not be used if portability is required. .Sh HISTORY A @@ -383,6 +395,10 @@ and .Fn mkostemps functions appeared in .Ox 5.7 . +The +.Fn mkdtemps +function appeared in +.Ox 7.5 . .Sh BUGS For .Fn mktemp -- cgit v1.2.3-55-g6feb