diff options
author | 1998-06-30 23:03:09 +0000 | |
---|---|---|
committer | 1998-06-30 23:03:09 +0000 | |
commit | a9567e1c19d7a05e85bf6df441572d47a4aeacbd (patch) | |
tree | 8c6df3de1b1c4b8ddf0b04cbbbb19486ed76cd4a /lib/libc/stdio/mktemp.c | |
parent | PCI-IDE interface include files (needed for Alpha, at least); from NetBSD. (diff) | |
download | wireguard-openbsd-a9567e1c19d7a05e85bf6df441572d47a4aeacbd.tar.xz wireguard-openbsd-a9567e1c19d7a05e85bf6df441572d47a4aeacbd.zip |
add mkstemp(char *template, int suffixlen) interface
Diffstat (limited to 'lib/libc/stdio/mktemp.c')
-rw-r--r-- | lib/libc/stdio/mktemp.c | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/lib/libc/stdio/mktemp.c b/lib/libc/stdio/mktemp.c index 53b40b027f3..a992e24f164 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.12 1998/04/14 19:25:11 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: mktemp.c,v 1.13 1998/06/30 23:03:13 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -44,7 +44,17 @@ static char rcsid[] = "$OpenBSD: mktemp.c,v 1.12 1998/04/14 19:25:11 deraadt Exp #include <ctype.h> #include <unistd.h> -static int _gettemp __P((char *, int *, int)); +static int _gettemp __P((char *, int *, int, int)); + +int +mkstemps(path, slen) + char *path; + int slen; +{ + int fd; + + return (_gettemp(path, &fd, 0, slen) ? fd : -1); +} int mkstemp(path) @@ -52,14 +62,14 @@ mkstemp(path) { int fd; - return (_gettemp(path, &fd, 0) ? fd : -1); + return (_gettemp(path, &fd, 0, 0) ? fd : -1); } char * mkdtemp(path) char *path; { - return(_gettemp(path, (int *)NULL, 1) ? path : (char *)NULL); + return(_gettemp(path, (int *)NULL, 1, 0) ? path : (char *)NULL); } char *_mktemp __P((char *)); @@ -68,7 +78,7 @@ char * _mktemp(path) char *path; { - return(_gettemp(path, (int *)NULL, 0) ? path : (char *)NULL); + return(_gettemp(path, (int *)NULL, 0, 0) ? path : (char *)NULL); } __warn_references(mktemp, @@ -83,12 +93,13 @@ mktemp(path) static int -_gettemp(path, doopen, domkdir) +_gettemp(path, doopen, domkdir, slen) char *path; register int *doopen; int domkdir; + int slen; { - register char *start, *trv; + register char *start, *trv, *suffp; struct stat sbuf; int pid, rval; @@ -97,10 +108,16 @@ _gettemp(path, doopen, domkdir) return(0); } - pid = getpid(); for (trv = path; *trv; ++trv) ; + trv -= slen; + suffp = trv; --trv; + if (trv < path) { + errno = EINVAL; + return (0); + } + pid = getpid(); while (*trv == 'X' && pid != 0) { *trv-- = (pid % 10) + '0'; pid /= 10; @@ -158,16 +175,21 @@ _gettemp(path, doopen, domkdir) /* tricky little algorithm for backward compatibility */ for (trv = start;;) { if (!*trv) - return(0); - if (*trv == 'Z') + return (0); + if (*trv == 'Z') { + if (trv == suffp) + return (0); *trv++ = 'a'; - else { + } else { if (isdigit(*trv)) *trv = 'a'; else if (*trv == 'z') /* inc from z to A */ *trv = 'A'; - else + else { + if (trv == suffp) + return (0); ++*trv; + } break; } } |