Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 Jan 1996 23:04:38 -0800
From:      Josh MacDonald <jmacd@CS.Berkeley.EDU>
To:        Nate Williams <nate@sri.mt.net>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: mktemp() sucks, why not fix it? 
Message-ID:  <199601120704.XAA07215@paris.CS.Berkeley.EDU>
In-Reply-To: Your message of "Thu, 11 Jan 1996 22:14:59 MST." <199601120514.WAA23403@rocky.sri.MT.net> 

next in thread | previous in thread | raw e-mail | index | archive | help

Sorry, that my strings were not writable misses the point.
That was my contrived example to illustrate the real problem,
which is not addressed by what you wrote.

Say that I malloced those segments and reread my message, that
wasn't the problem.  I was calling mktemp on heap allocated
memory segments in my program when I stumbled upon this problem.

-josh

> I'll be the first call to mktemp fails as well, unless you happen to be
> compiling with -fwritable-strings.
> 
> You have to pass in data to mktemp which can be modified, which neither
> of the above strings can be.
> 
> Try this instead:
> int
> main()
> {
>     char buf1[255], buf2[255];
> 
>     strcpy(buf1, "/tmp/foo.XXXXXX");
>     strcpy(buf2, "/tmp/foo.XXXXXX");
>     if ( mktemp(buf1) == NULL )
>         perror("mktemp() failed");
>     symlink("/tmp/existsbutnotdirectory/foo", buf1);
>     if(mktemp(buf2) == NULL)
>         perror("mktemp() failed");
>     printf("buf1 = %s\nbuf2 = %s\n", buf1, buf2);
> }
> 
> 
> Nate



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199601120704.XAA07215>