diff options
| author | svn2git <svn2git@FreeBSD.org> | 1994-05-01 08:00:00 +0000 | 
|---|---|---|
| committer | svn2git <svn2git@FreeBSD.org> | 1994-05-01 08:00:00 +0000 | 
| commit | a16f65c7d117419bd266c28a1901ef129a337569 (patch) | |
| tree | 2626602f66dc3551e7a7c7bc9ad763c3bc7ab40a /lib/libc/stdio/tempnam.c | |
| parent | 8503f4f13f77abf7adc8f7e329c6f9c1d52b6a20 (diff) | |
Diffstat (limited to 'lib/libc/stdio/tempnam.c')
| -rw-r--r-- | lib/libc/stdio/tempnam.c | 22 | 
1 files changed, 16 insertions, 6 deletions
| diff --git a/lib/libc/stdio/tempnam.c b/lib/libc/stdio/tempnam.c index 988763aac5b8..e3ee6c072f05 100644 --- a/lib/libc/stdio/tempnam.c +++ b/lib/libc/stdio/tempnam.c @@ -48,6 +48,8 @@ tempnam(dir, pfx)  {  	int sverrno;  	char *f, *name; +	static char unique[] = "@AA"; +	int idx;  	if (!(name = malloc(MAXPATHLEN)))  		return(NULL); @@ -55,27 +57,35 @@ tempnam(dir, pfx)  	if (!pfx)  		pfx = "tmp."; +	/* Bump up the unique counter.  The following is also a gross abuse +	 * of C, but I don't really care.  This whole function is superceeded +	 * by mkstemp() anyway. +	 */ +	idx = unique[0] < 'Z' ? 0 : unique[1] < 'Z' ? 1 : unique[2] < 'Z' ? +	    2 : (int)strcpy(unique, "AAA"), 0; +	++unique[idx]; +  	if (f = getenv("TMPDIR")) { -		(void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, -			*(f + strlen(f) - 1) == '/'? "": "/", pfx); +		(void)snprintf(name, MAXPATHLEN, "%s%s%s%sXXXXXX", f, +			*(f + strlen(f) - 1) == '/'? "": "/", pfx, unique);  		if (f = mktemp(name))  			return(f);  	}  	if (f = (char *)dir) { -		(void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, -			*(f + strlen(f) - 1) == '/'? "": "/", pfx); +		(void)snprintf(name, MAXPATHLEN, "%s%s%s%sXXXXXX", f, +			*(f + strlen(f) - 1) == '/'? "": "/", pfx, unique);  		if (f = mktemp(name))  			return(f);  	}  	f = P_tmpdir; -	(void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx); +	(void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, pfx, unique);  	if (f = mktemp(name))  		return(f);  	f = _PATH_TMP; -	(void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx); +	(void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, pfx, unique);  	if (f = mktemp(name))  		return(f); | 
