diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2024-03-01 21:30:41 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2024-03-01 21:30:41 +0000 |
commit | 5e1c66d66cc28f1eb05dc9127b4f0d62400b54f9 (patch) | |
tree | 3853fb62c4b6fca29011a11c7ab2ea71c28b3e3c /lib/libc/stdlib | |
parent | b59be6af76401428f142de3e0e7d16c1bacfcfb8 (diff) |
Add mkdtemps(3), like mkdtemp(3) but with a suffix.
OK deraadt@ tb@
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r-- | lib/libc/stdlib/mkdtemp.c | 10 | ||||
-rw-r--r-- | lib/libc/stdlib/mktemp.3 | 30 |
2 files changed, 32 insertions, 8 deletions
diff --git a/lib/libc/stdlib/mkdtemp.c b/lib/libc/stdlib/mkdtemp.c index c33c3b4e8bb..c11501f8933 100644 --- a/lib/libc/stdlib/mkdtemp.c +++ b/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/lib/libc/stdlib/mktemp.3 b/lib/libc/stdlib/mktemp.3 index d4bd7bdc91b..83b7c9eb301 100644 --- a/lib/libc/stdlib/mktemp.3 +++ b/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 |