Date: Sun, 20 Oct 1996 20:56:37 -0600 (MDT) From: Marc Slemko <marcs@znep.com> To: Ron Bolin <rlb@mindspring.com> Cc: freebsd-current@FreeBSD.org Subject: Re: mktemp BUG? Message-ID: <Pine.BSF.3.95.961020205133.15603G-100000@alive.ampr.ab.ca> In-Reply-To: <326AD788.167EB0E7@mindspring.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Check the man page for mktemp: >NOTES > A common problem that results in a core dump is that the programmer pass- > es in a read-only string to mktemp() or mkstemp(). This is common with > programs that were developed before ISO 9899: 1990 (``ISO C'') compilers > were common. For example, calling mkstemp() with an argument of > "/tmp/tempfile.XXXXXX" will result in a core dump due to mkstemp() at- > tempting to modify the string constant that was given. If the program in > question makes heavy use of that type of function call, you do have the > option of compiling the program so that it will store string constants in > a writable segment of memory. See gcc(1) for more information. Try something like: #include <unistd.h> #include <stdio.h> int main () { char *tmp; char filename[80]; strcpy(filename, "/tmp/cp.XXXXX"); tmp = mktemp(filename); printf("file: %s (%p, %p)\n", tmp, tmp, filename); return 0; } Yes, mktemp is a bit strange. On Sun, 20 Oct 1996, Ron Bolin wrote: > Just checking my system and sanity. The mktemp(char *) function > dumps core everytime. Seems to be a problem in the C lib version. > Can anyone else duplicate this bug? > #include <stdlib.h> > char *tmp = mktemp("/tmp/cp.XXXXXX");
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.95.961020205133.15603G-100000>