diff options
author | 1997-10-07 22:21:33 +0000 | |
---|---|---|
committer | 1997-10-07 22:21:33 +0000 | |
commit | 642b82b4777389b87f66bae6947e03d853e98e80 (patch) | |
tree | c0586d331c469eb2ea5bd7247553a762c866fe38 /lib/libc/stdio/mktemp.c | |
parent | Audio stuff from NetBSD (diff) | |
download | wireguard-openbsd-642b82b4777389b87f66bae6947e03d853e98e80.tar.xz wireguard-openbsd-642b82b4777389b87f66bae6947e03d853e98e80.zip |
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.
Diffstat (limited to 'lib/libc/stdio/mktemp.c')
-rw-r--r-- | lib/libc/stdio/mktemp.c | 32 |
1 files changed, 17 insertions, 15 deletions
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; } } |