Re: [PHP3] tempnam() question. From: Richard Lynch (rlynch <email protected>)
Date: 11/30/99

I'm probably wrong, but I think the low-level mktemp() function called here
is a Unix OS function returning a 6-character filename... So it doesn't
matter how you sprintf() it, it's gonna be six characters.

There may be an optional argument to mktemp or something though...

At 02:46 PM 11/30/99 -0500, you wrote:
>Hi,
>
>I'm trying to use tempnam() to make unique names for temp files, but the
>limit on the filename is about 6 characters. Which means I can only get
>6 unique characters after the prefix.
>
>I tried to modify ext/standard/file.c, and added about 20 X's.
>
>After recompiling php source, and apache source, the tempnam() function
>still makes 6 character unique names.
>
>I even set the MAXPATHLEN to 255, am I missing something?
>
>I'm scratching my head over this.
>
>I'm including my patch for ext/standard/file.c, if anyone can take a
>look, it would be greately appreciated.
>
>Thanks,
>Tris
>
>--- php-4.0b2/ext/standard/file.c Mon Aug 2 15:16:50 1999
>+++ php-4.0b2a/ext/standard/file.c Tue Nov 30 13:49:10 1999
>@@ -123,13 +123,7 @@
> # include <unistd.h>
> #endif
>
>-#ifndef MAXPATHLEN
>-# ifdef PATH_MAX
>-# define MAXPATHLEN PATH_MAX
>-# else
> # define MAXPATHLEN 255
>-# endif
>-#endif
>
>
> char *tempnam(const char *dir, const char *pfx)
>@@ -138,38 +132,43 @@
> char *f, *name;
> static char path_tmp[] = "/tmp";
>
>- if (!(name = emalloc(MAXPATHLEN))) {
>+ if (!(name = emalloc(255))) {
> return(NULL);
> }
>
>+/*
> if (!pfx) {
> pfx = "tmp.";
> }
>+*/
>
>+ sprintf(name,"%s%sXXXXXXXXXXXXXXXXXXXXXXX",dir,pfx);
>+ if(f=mktemp(name)) return(f);
>+/*
> if (f = getenv("TMPDIR")) {
>- (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f,
>+ (void)sprintf(name, "%s%s%sXXXXXXXXXXX", f,
> *(f + strlen(f) - 1) == '/'? "": "/", pfx);
> if (f = mktemp(name))
> return(f);
> }
>
> if (f = (char *)dir) {
>- (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f,
>+ (void)sprintf(name, "%s%s%sXXXXXXXXXXX", f,
> *(f + strlen(f) - 1) == '/'? "": "/", pfx);
> if (f = mktemp(name))
> return(f);
> }
>
> f = P_tmpdir;
>- (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx);
>+ (void)sprintf(name, "%s%sXXXXXXXXXXX", f, pfx);
> if (f = mktemp(name))
> return(f);
>
> f = path_tmp;
>- (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx);
>+ (void)sprintf(name, "%s%sXXXXXXXXXXX", f, pfx);
> if (f = mktemp(name))
> return(f);
>-
>+*/
> save_errno = errno;
> efree(name);
> errno = save_errno;
>
>--
>PHP 3 Mailing List <http://www.php.net/>
>To unsubscribe, send an empty message to php3-unsubscribe <email protected>
>To subscribe to the digest, e-mail: php3-digest-subscribe <email protected>
>To search the mailing list archive, go to: http://www.php.net/mailsearch.php3
>To contact the list administrators, e-mail: php-list-admin <email protected>

-- 
"TANSTAAFL"
http://CHaTMusic.com                       http://EmphasisEntertainment.com
http://L-I-E.com                           http://JadeMaze.com
http://CatCatalani.com                     http://MGMH.com
http://AstraKelly.com                      http://OlivierLedoux.com
http://VoodooKings.net                     http://UncommonGround.com

-- PHP 3 Mailing List <http://www.php.net/> To unsubscribe, send an empty message to php3-unsubscribe <email protected> To subscribe to the digest, e-mail: php3-digest-subscribe <email protected> To search the mailing list archive, go to: http://www.php.net/mailsearch.php3 To contact the list administrators, e-mail: php-list-admin <email protected>