diff options
| author | millert <> | 2024-03-01 21:30:40 +0000 |
|---|---|---|
| committer | millert <> | 2024-03-01 21:30:40 +0000 |
| commit | 00c9df314d126a5ad9b4c7debf8ca32c053a7afb (patch) | |
| tree | 6dca38d540d682ccd75c17226aef4504204a614a /src/lib | |
| parent | 245fea5e3816a266f8a4d57c27c1a8eae49ef975 (diff) | |
| download | openbsd-00c9df314d126a5ad9b4c7debf8ca32c053a7afb.tar.gz openbsd-00c9df314d126a5ad9b4c7debf8ca32c053a7afb.tar.bz2 openbsd-00c9df314d126a5ad9b4c7debf8ca32c053a7afb.zip | |
Add mkdtemps(3), like mkdtemp(3) but with a suffix.
OK deraadt@ tb@
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/libc/stdlib/mkdtemp.c | 10 | ||||
| -rw-r--r-- | src/lib/libc/stdlib/mktemp.3 | 30 |
2 files changed, 32 insertions, 8 deletions
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 @@ | |||
| 1 | /* $OpenBSD: mkdtemp.c,v 1.1 2024/01/19 19:45:02 millert Exp $ */ | 1 | /* $OpenBSD: mkdtemp.c,v 1.2 2024/03/01 21:30:40 millert Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2024 Todd C. Miller | 3 | * Copyright (c) 2024 Todd C. Miller |
| 4 | * | 4 | * |
| @@ -31,3 +31,11 @@ mkdtemp(char *path) | |||
| 31 | return path; | 31 | return path; |
| 32 | return NULL; | 32 | return NULL; |
| 33 | } | 33 | } |
| 34 | |||
| 35 | char * | ||
| 36 | mkdtemps(char *path, int slen) | ||
| 37 | { | ||
| 38 | if (__mktemp4(path, slen, 0, mkdtemp_cb) == 0) | ||
| 39 | return path; | ||
| 40 | return NULL; | ||
| 41 | } | ||
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 @@ | |||
| 1 | .\" $OpenBSD: mktemp.3,v 1.1 2024/01/19 16:30:28 millert Exp $ | 1 | .\" $OpenBSD: mktemp.3,v 1.2 2024/03/01 21:30:40 millert 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,7 +27,7 @@ | |||
| 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: January 19 2024 $ | 30 | .Dd $Mdocdate: March 1 2024 $ |
| 31 | .Dt MKTEMP 3 | 31 | .Dt MKTEMP 3 |
| 32 | .Os | 32 | .Os |
| 33 | .Sh NAME | 33 | .Sh NAME |
| @@ -36,7 +36,8 @@ | |||
| 36 | .Nm mkostemp , | 36 | .Nm mkostemp , |
| 37 | .Nm mkstemps , | 37 | .Nm mkstemps , |
| 38 | .Nm mkostemps , | 38 | .Nm mkostemps , |
| 39 | .Nm mkdtemp | 39 | .Nm mkdtemp , |
| 40 | .Nm mkdtemps | ||
| 40 | .Nd make temporary file name (unique) | 41 | .Nd make temporary file name (unique) |
| 41 | .Sh SYNOPSIS | 42 | .Sh SYNOPSIS |
| 42 | .In stdlib.h | 43 | .In stdlib.h |
| @@ -48,6 +49,8 @@ | |||
| 48 | .Fn mkstemps "char *template" "int suffixlen" | 49 | .Fn mkstemps "char *template" "int suffixlen" |
| 49 | .Ft char * | 50 | .Ft char * |
| 50 | .Fn mkdtemp "char *template" | 51 | .Fn mkdtemp "char *template" |
| 52 | .Ft char * | ||
| 53 | .Fn mkdtemps "char *template" "int suffixlen" | ||
| 51 | .In stdlib.h | 54 | .In stdlib.h |
| 52 | .In fcntl.h | 55 | .In fcntl.h |
| 53 | .Ft int | 56 | .Ft int |
| @@ -142,11 +145,19 @@ The | |||
| 142 | function makes the same replacement to the template as in | 145 | function makes the same replacement to the template as in |
| 143 | .Fn mktemp | 146 | .Fn mktemp |
| 144 | and creates the template directory, mode 0700. | 147 | and creates the template directory, mode 0700. |
| 148 | The | ||
| 149 | .Fn mkdtemps | ||
| 150 | function acts the same as | ||
| 151 | .Fn mkdtemp , | ||
| 152 | except that it permits a suffix to exist in the template, | ||
| 153 | similar to | ||
| 154 | .Fn mkstemps . | ||
| 145 | .Sh RETURN VALUES | 155 | .Sh RETURN VALUES |
| 146 | The | 156 | The |
| 147 | .Fn mktemp | 157 | .Fn mktemp , |
| 158 | .Fn mkdtemp , | ||
| 148 | and | 159 | and |
| 149 | .Fn mkdtemp | 160 | .Fn mkdtemps |
| 150 | functions return a pointer to the template on success and | 161 | functions return a pointer to the template on success and |
| 151 | .Dv NULL | 162 | .Dv NULL |
| 152 | on failure. | 163 | on failure. |
| @@ -356,9 +367,10 @@ as of | |||
| 356 | it is no longer a part of the standard. | 367 | it is no longer a part of the standard. |
| 357 | .Pp | 368 | .Pp |
| 358 | The | 369 | The |
| 359 | .Fn mkstemps | 370 | .Fn mkstemps , |
| 371 | .Fn mkostemps , | ||
| 360 | and | 372 | and |
| 361 | .Fn mkostemps | 373 | .Fn mkdtemps |
| 362 | functions are non-standard and should not be used if portability is required. | 374 | functions are non-standard and should not be used if portability is required. |
| 363 | .Sh HISTORY | 375 | .Sh HISTORY |
| 364 | A | 376 | A |
| @@ -383,6 +395,10 @@ and | |||
| 383 | .Fn mkostemps | 395 | .Fn mkostemps |
| 384 | functions appeared in | 396 | functions appeared in |
| 385 | .Ox 5.7 . | 397 | .Ox 5.7 . |
| 398 | The | ||
| 399 | .Fn mkdtemps | ||
| 400 | function appeared in | ||
| 401 | .Ox 7.5 . | ||
| 386 | .Sh BUGS | 402 | .Sh BUGS |
| 387 | For | 403 | For |
| 388 | .Fn mktemp | 404 | .Fn mktemp |
