summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>1997-06-17 15:34:27 +0000
committermillert <millert@openbsd.org>1997-06-17 15:34:27 +0000
commit9a2404e359cb6584364e72403a813ead22e3d03e (patch)
tree082e234c9f8d5cf3a6c412858bea4b15a9d33d46
parentmake 'ifconfig -a' and 'ifconfig de0' print full ifaliases output. this (diff)
downloadwireguard-openbsd-9a2404e359cb6584364e72403a813ead22e3d03e.tar.xz
wireguard-openbsd-9a2404e359cb6584364e72403a813ead22e3d03e.zip
Adds a -d (directory) flag.
-rw-r--r--usr.bin/mktemp/mktemp.113
-rw-r--r--usr.bin/mktemp/mktemp.c58
2 files changed, 50 insertions, 21 deletions
diff --git a/usr.bin/mktemp/mktemp.1 b/usr.bin/mktemp/mktemp.1
index 17efe8d163c..024bbdea56c 100644
--- a/usr.bin/mktemp/mktemp.1
+++ b/usr.bin/mktemp/mktemp.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: mktemp.1,v 1.4 1997/05/30 07:49:25 deraadt Exp $
+.\" $OpenBSD: mktemp.1,v 1.5 1997/06/17 15:34:27 millert Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -39,8 +39,9 @@
.Nd make temporary file name (unique)
.Sh SYNOPSIS
.Nm mktemp
-.Op Fl u
+.Op Fl d
.Op Fl q
+.Op Fl u
.Ar template
.Sh DESCRIPTION
The
@@ -78,6 +79,11 @@ to standard output.
.Sh OPTIONS
.Bl -tag -width indent
The available options are as follows:
+.It Fl d
+Make a directory instead of a file.
+.It Fl q
+Fail silently if an error occurs. This is useful if
+a script does not want error output to go to standard error.
.It Fl u
Operate in
.Dq unsafe
@@ -87,9 +93,6 @@ exits. This is slightly better than
.Fn mktemp 3
but still introduces a race condition. Use of this
option is not encouraged.
-.It Fl q
-Fail silently if an error occurs. This is useful if
-a script does not want error output to go to standard error.
.Sh RETURN VALUES
The
.Nm
diff --git a/usr.bin/mktemp/mktemp.c b/usr.bin/mktemp/mktemp.c
index 6ebeb1cb7ae..1d89955fb56 100644
--- a/usr.bin/mktemp/mktemp.c
+++ b/usr.bin/mktemp/mktemp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mktemp.c,v 1.2 1997/01/03 22:49:22 millert Exp $ */
+/* $OpenBSD: mktemp.c,v 1.3 1997/06/17 15:34:29 millert Exp $ */
/*
* Copyright (c) 1996 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -31,7 +31,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: mktemp.c,v 1.2 1997/01/03 22:49:22 millert Exp $";
+static char rcsid[] = "$OpenBSD: mktemp.c,v 1.3 1997/06/17 15:34:29 millert Exp $";
#endif /* not lint */
#include <stdio.h>
@@ -45,7 +45,8 @@ extern char *__progname;
void
usage()
{
- (void) fprintf(stderr, "Usage: %s [-u] [-q] template\n", __progname);
+ (void) fprintf(stderr, "Usage: %s [-d] [-q] [-u] template\n",
+ __progname);
exit(1);
}
@@ -55,16 +56,19 @@ main(argc, argv)
char **argv;
{
char *template;
- int ch, uflag = 0, qflag = 0;
+ int c, uflag = 0, qflag = 0, makedir = 0;
- while ((ch = getopt(argc, argv, "uq")) != -1)
- switch(ch) {
- case 'u':
- uflag = 1;
+ while ((c = getopt(argc, argv, "dqu")) != -1)
+ switch(c) {
+ case 'd':
+ makedir = 1;
break;
case 'q':
qflag = 1;
break;
+ case 'u':
+ uflag = 1;
+ break;
case '?':
default:
usage();
@@ -80,15 +84,37 @@ main(argc, argv)
errx(1, "Cannot allocate memory");
}
- if (mkstemp(template) < 0) {
- if (qflag)
- exit(1);
- else
- err(1, "Cannot create temp file %s", template);
- }
+ if (makedir) {
+ for (c = 0; c < 100; c++) {
+ if (mktemp(template) == NULL)
+ if (qflag)
+ exit(1);
+ else
+ err(1, "Cannot create temp dir %s",
+ template);
+ if (mkdir(template, 0700) == 0)
+ break;
+ }
+ if (c >= 100) {
+ if (qflag)
+ exit(1);
+ else
+ err(1, "Cannot make temp dir %s", template);
+ }
- if (uflag)
- (void) unlink(template);
+ if (uflag)
+ (void) rmdir(template);
+ } else {
+ if (mkstemp(template) < 0) {
+ if (qflag)
+ exit(1);
+ else
+ err(1, "Cannot create temp file %s", template);
+ }
+
+ if (uflag)
+ (void) unlink(template);
+ }
(void) puts(template);
free(template);