diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2009-07-03 13:01:17 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2009-07-03 13:01:17 +0000 |
commit | e5f37aa1482293d5b22491a38ab4995875943754 (patch) | |
tree | f033de3f84a00794040db30f57675343966f4636 /winsup/cygwin/mktemp.cc | |
parent | c52ac05c3a213c3016b18693d6b3457448404e53 (diff) | |
download | cygnal-e5f37aa1482293d5b22491a38ab4995875943754.tar.gz cygnal-e5f37aa1482293d5b22491a38ab4995875943754.tar.bz2 cygnal-e5f37aa1482293d5b22491a38ab4995875943754.zip |
* cygwin.din (fpurge, mkstemps): New exports.
* include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump.
* mktemp.cc (_gettemp): Add parameter.
(mkstemps): New function.
(mkstemp, mkdtemp, mktemp): Adjust clients.
Diffstat (limited to 'winsup/cygwin/mktemp.cc')
-rw-r--r-- | winsup/cygwin/mktemp.cc | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/winsup/cygwin/mktemp.cc b/winsup/cygwin/mktemp.cc index c39fe49be..b8a1381c4 100644 --- a/winsup/cygwin/mktemp.cc +++ b/winsup/cygwin/mktemp.cc @@ -1,15 +1,16 @@ /* mktemp.cc: mktemp functions -This file is adapted for Cygwin from FreeBSD. +This file is adapted for Cygwin from FreeBSD and newlib. See the copyright at the bottom of this file. */ #include "winsup.h" #include "cygerrno.h" #include <fcntl.h> +#include <sys/stat.h> #include <unistd.h> -static int _gettemp(char *, int *, int); +static int _gettemp(char *, int *, int, size_t); static uint32_t arc4random (); static const char padchar[] = @@ -19,23 +20,30 @@ extern "C" int mkstemp(char *path) { int fd; - return _gettemp(path, &fd, 0) ? fd : -1; + return _gettemp(path, &fd, 0, 0) ? fd : -1; } extern "C" char * mkdtemp(char *path) { - return _gettemp(path, NULL, 1) ? path : NULL; + return _gettemp(path, NULL, 1, 0) ? path : NULL; +} + +extern "C" int +mkstemps(char *path, int len) +{ + int fd; + return _gettemp(path, &fd, 0, len) ? fd : -1; } extern "C" char * mktemp(char *path) { - return _gettemp(path, NULL, 0) ? path : (char *) NULL; + return _gettemp(path, NULL, 0, 0) ? path : (char *) NULL; } static int -_gettemp(char *path, int *doopen, int domkdir) +_gettemp(char *path, int *doopen, int domkdir, size_t suffixlen) { char *start, *trv, *suffp; char *pad; @@ -46,12 +54,14 @@ _gettemp(char *path, int *doopen, int domkdir) return 0; } - suffp = trv = strchr (path, '\0'); - if (--trv < path) + trv = strchr (path, '\0'); + if ((size_t) (trv - path) < suffixlen) { set_errno (EINVAL); return 0; } + trv -= suffixlen; + suffp = trv--; /* Fill space with random characters */ while (trv >= path && *trv == 'X') @@ -59,6 +69,11 @@ _gettemp(char *path, int *doopen, int domkdir) uint32_t rand = arc4random () % (sizeof (padchar) - 1); *trv-- = padchar[rand]; } + if (suffp - trv < 6) + { + set_errno (EINVAL); + return 0; + } start = trv + 1; /* |