tmpnam() core dumping

Tim Hollebeek tim@wagner.Princeton.EDU
Fri Dec 12 15:46:00 GMT 1997


Bill Ahlbrandt writes ...
> 
> Yes, using -fwritable-strings fixes the problem.
> 
> I wonder why these functions want to modify the string that is passed to them :-)?

Normal behavior.  Otherwise they would have to call malloc() to allocate the
result, or something similar.  E.g. from the IRIX man page:

     tmpnam always generates a file name using the path-prefix defined as
     P_tmpdir in the <stdio.h> header file.  If s is NULL, tmpnam leaves its
     result in an internal static area and returns a pointer to that area.
     The next call to tmpnam will destroy the contents of the area.  If s is
     not NULL, it is assumed to be the address of an array of at least
     L_tmpnam bytes, where L_tmpnam is a constant defined in <stdio.h>; tmpnam
     places its result in that array and returns s.

---------------------------------------------------------------------------
Tim Hollebeek                           | "Everything above is a true
email: tim@wfn-shop.princeton.edu       |  statement, for sufficiently
URL: http://wfn-shop.princeton.edu/~tim |  false values of true."



More information about the Gcc mailing list