mkstemp in Haskell

Martin Sjögren md9ms@mdstud.chalmers.se
27 May 2003 11:40:26 +0200


--=-SUykac5Oxz63DgQxrMgO
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

tis 2003-05-27 klockan 11.25 skrev Peter Simons:
> Martin Norb=E4ck writes:
>=20
>  > [...] perhaps you want to return (String, Handle) so that you know
>  > the file name (in case you want to do something else than just
>  > reading/writing from it).
>=20
> IMHO there should be a way to obtain _only_ the generated file name,
> without opening a file at all, because I may want to use this name to
> create a _directory_ rather than a file.

There's  char *mktemp(char *template)  but it's not Safe:

BUGS  Never use mktemp(). Some implementations follow BSD 4.3 and
replace XXXXXX by the current  process  id and a single letter, so that
at most 26 different names can be returned.  Since on the one hand the
names are easy to guess, and on the other hand there is  a  race=20
between  testing whether  the  name  exists and opening the file, every
use of mktemp() is a security risk.  The race is avoided by mkstemp(3).

There is, however, also  char *mkdtemp(char *template)  (available in
openbsd 2.2+ and glibc 2.1.91, can't speak for others) which is also
easy to wrap.


/Martin
--=20
Martin Sj=F6gren
  sjogren@debian.org -- marvin@dum.chalmers.se
  GPG key: http://www.mdstud.chalmers.se/~md9ms/gpg.html
  let hello =3D "hello" : hello in putStr (unlines hello)

--=-SUykac5Oxz63DgQxrMgO
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: Detta =?ISO-8859-1?Q?=E4r?= en digitalt signerad
	meddelandedel

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQA+0zKKGpBPiZwE9FYRAqnsAJ40wzn7UNu8DwCz2w6AbVw14ziZzgCfeWFH
jnoGvkR4EQlM9hTyIrjU/IE=
=iWps
-----END PGP SIGNATURE-----

--=-SUykac5Oxz63DgQxrMgO--