[patch] use mkstemp instead of mktemp.

Muthukumar Ratty muthu@iqmail.net
Wed Jul 2 04:19:00 GMT 2003


>
> You can't just mechanically replace mktemp() with mkstemp().  They
> have different return values.
>mkstemp() returns the newly opened
> file.

and also modifies the template properly so I think it should be ok.

>Not using that return value is an error.  So the code needs to
> be rewritten.  But you can't rewrite it trivially; some calls to
> make_tempname() use the result to create a directory, and that can't
> be done using mkstemp().

this is getting complicated :) how about the following.

like Alan mentioned check for the mkstemp and mkdtemp. if they exist then
use them otherwise fall back to mktemp. but how do we know if the calling
function wants a file or directory? Add another argument to
make_tempname? (any other suggestions?).

Also I looked at the fucntions that call make_tempname.
Its ok in ar.c:write_archive(), but in objcopy, make_tempname for dir is
followed by MKDIR. so we need to do the HAVE_MKDTEMP check there also and
fall back to MKDIR.

Does this sound ok? Also mkstemp opens the file... that increments
the file reference count? So close it in make_tempname before returning?

Now I know why the "danger" warning was not cleared :)

>
> Also, mkstemp() is not available on all systems, so binutils code
> shouldn't call it unless a replacement version is put into libiberty.
> libiberty already has mkstemps(), which is a minor extension of
> mkstemp(); for the binutils, it would probably be better to use that
> rather than mkstemp().
>
> Ian
>





More information about the Binutils mailing list