summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1997-10-07 22:21:35 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1997-10-07 22:21:35 +0000
commit8a28f020ad85f30634fc6cda859e198dedbaf669 (patch)
treeba74cc2137224e2c398c365c2c5713c30ee4b5cc
parentca7c0b7be348ee6e20a9e029457b2cb54955cd39 (diff)
1) Don't truncate the input string when a directory cannot be stat'd
2) Use traditional mktemp(3) semantics. Don't return an error if directories in the path don't exist yet for mktemp(3) only.
-rw-r--r--lib/libc/stdio/mktemp.34
-rw-r--r--lib/libc/stdio/mktemp.c32
2 files changed, 18 insertions, 18 deletions
diff --git a/lib/libc/stdio/mktemp.3 b/lib/libc/stdio/mktemp.3
index f0c0866ae09..94020563289 100644
--- a/lib/libc/stdio/mktemp.3
+++ b/lib/libc/stdio/mktemp.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: mktemp.3,v 1.4 1997/06/20 04:10:18 millert Exp $
+.\" $OpenBSD: mktemp.3,v 1.5 1997/10/07 22:21:33 millert Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -102,7 +102,6 @@ If either call fails an error code is placed in the global variable
.Va errno .
.Sh ERRORS
The
-.Fn mktemp ,
.Fn mkstemp
and
.Fn mkdtemp
@@ -116,7 +115,6 @@ The pathname portion of the template is not an existing directory.
.El
.Pp
The
-.Fn mktemp ,
.Fn mkstemp
and
.Fn mkdtemp
diff --git a/lib/libc/stdio/mktemp.c b/lib/libc/stdio/mktemp.c
index 1dcbc02b8d4..d54deceb503 100644
--- a/lib/libc/stdio/mktemp.c
+++ b/lib/libc/stdio/mktemp.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: mktemp.c,v 1.9 1997/06/20 04:10:19 millert Exp $";
+static char rcsid[] = "$OpenBSD: mktemp.c,v 1.10 1997/10/07 22:21:34 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -88,10 +88,9 @@ _gettemp(path, doopen, domkdir)
register int *doopen;
int domkdir;
{
- extern int errno;
register char *start, *trv;
struct stat sbuf;
- int pid;
+ int pid, rval;
if (doopen && domkdir) {
errno = EINVAL;
@@ -121,19 +120,22 @@ _gettemp(path, doopen, domkdir)
* check the target directory; if you have six X's and it
* doesn't exist this runs for a *very* long time.
*/
- for (start = trv + 1;; --trv) {
- if (trv <= path)
- break;
- if (*trv == '/') {
- *trv = '\0';
- if (stat(path, &sbuf))
- return(0);
- if (!S_ISDIR(sbuf.st_mode)) {
- errno = ENOTDIR;
- return(0);
+ if (doopen || domkdir) {
+ for (start = trv + 1;; --trv) {
+ if (trv <= path)
+ break;
+ if (*trv == '/') {
+ *trv = '\0';
+ rval = stat(path, &sbuf);
+ *trv = '/';
+ if (rval != 0)
+ return(0);
+ if (!S_ISDIR(sbuf.st_mode)) {
+ errno = ENOTDIR;
+ return(0);
+ }
+ break;
}
- *trv = '/';
- break;
}
}