
Dear list. I needed a function for creating temporary files. Since I couldn't find one in the standard library, I just hacked one up using the ffi. It's in the haskell-libs cvs [1]. I've got an icky import of GHC.Handle to get openFd, any way I could get rid of it? (fdToHandle isn't enough) [1] http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/haskell-libs/libs/... /Martin PS: I slapped an LGPL license on it, if that's a problem, it's negotiable. -- Martin Sjögren sjogren@debian.org -- marvin@dum.chalmers.se GPG key: http://www.mdstud.chalmers.se/~md9ms/gpg.html let hello = "hello" : hello in putStr (unlines hello)

In local.libraries, you wrote:
I needed a function for creating temporary files. Since I couldn't find one in the standard library, I just hacked one up using the ffi. It's in the haskell-libs cvs [1]. I've got an icky import of GHC.Handle to get openFd, any way I could get rid of it? (fdToHandle isn't enough)
It's in the Posix Spec, so we might as well put it in System.Posix. -- http://www-i2.informatik.rwth-aachen.de/stolz/ *** PGP *** S/MIME rage against the finite state machine

tis 2003-05-27 klockan 09.20 skrev Volker Stolz:
In local.libraries, you wrote:
I needed a function for creating temporary files. Since I couldn't find one in the standard library, I just hacked one up using the ffi. It's in the haskell-libs cvs [1]. I've got an icky import of GHC.Handle to get openFd, any way I could get rid of it? (fdToHandle isn't enough)
It's in the Posix Spec, so we might as well put it in System.Posix.
Yes, and 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). Oh, and on an almost but not completely unrelated note, why not use the hierarchical namespace for all the other haskell-libs projects as well? I just put some code into haskell-i18n (http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/haskell-i18n/Source/Text/I18N...) maybe we should use the same repository? Regards, Martin -- Martin Norbäck d95mback@dtek.chalmers.se Kapplandsgatan 40 +46 (0)708 26 33 60 S-414 78 GÖTEBORG http://www.dtek.chalmers.se/~d95mback/ SWEDEN OpenPGP ID: 3FA8580B

tis 2003-05-27 klockan 10.42 skrev Martin Norbäck:
tis 2003-05-27 klockan 09.20 skrev Volker Stolz:
In local.libraries, you wrote:
I needed a function for creating temporary files. Since I couldn't find one in the standard library, I just hacked one up using the ffi. It's in the haskell-libs cvs [1]. I've got an icky import of GHC.Handle to get openFd, any way I could get rid of it? (fdToHandle isn't enough)
It's in the Posix Spec, so we might as well put it in System.Posix.
Yes, and 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).
Well, I peek at the CString and use that as the file name when creating the Handle. I assumed that there was a way to get this from the Handle (other than the Show instance that is). Maybe there isn't? /Martin -- Martin Sjögren sjogren@debian.org -- marvin@dum.chalmers.se GPG key: http://www.mdstud.chalmers.se/~md9ms/gpg.html let hello = "hello" : hello in putStr (unlines hello)

Martin Norbäck writes:
[...] 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).
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. Peter

tis 2003-05-27 klockan 11.25 skrev Peter Simons:
Martin Norbäck writes:
[...] 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).
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 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 -- Martin Sjögren sjogren@debian.org -- marvin@dum.chalmers.se GPG key: http://www.mdstud.chalmers.se/~md9ms/gpg.html let hello = "hello" : hello in putStr (unlines hello)

Martin Sjögren writes:
[...] there is a race 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).
That's true (unless you start looking at file systems like NFS, etc.), but if I _need_ to create a temporary directory, it's not like I have an alternative. :-| Peter
participants (4)
-
Martin Norbäck
-
Martin Sjögren
-
Peter Simons
-
Volker Stolz