From owner-freebsd-hackers Thu Jan 11 23:04:52 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id XAA03006 for hackers-outgoing; Thu, 11 Jan 1996 23:04:52 -0800 (PST) Received: from paris.CS.Berkeley.EDU (paris.CS.Berkeley.EDU [128.32.34.47]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id XAA02998 for ; Thu, 11 Jan 1996 23:04:44 -0800 (PST) Received: from paris.CS.Berkeley.EDU (localhost.Berkeley.EDU [127.0.0.1]) by paris.CS.Berkeley.EDU (8.6.11/8.6.9) with ESMTP id XAA07215; Thu, 11 Jan 1996 23:04:39 -0800 From: Josh MacDonald Message-Id: <199601120704.XAA07215@paris.CS.Berkeley.EDU> To: Nate Williams cc: freebsd-hackers@freebsd.org Subject: Re: mktemp() sucks, why not fix it? In-reply-to: Your message of "Thu, 11 Jan 1996 22:14:59 MST." <199601120514.WAA23403@rocky.sri.MT.net> Date: Thu, 11 Jan 1996 23:04:38 -0800 Sender: owner-hackers@freebsd.org Precedence: bulk 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