
On 20 December 2004 22:01, John Goerzen wrote:
There appears to be no interface in Haskell to ftruncate(2). (Or, for that matter, the less-useful truncate(2)).
There are System.Posix.setFileSize and System.Posix.setFdSize, which are direct interfaces to truncate(2) and ftruncate(2) respectively. However, perhaps you want something more portable. I seem to recall there was a proposal to add hSetFileSize at one point... ah yes: http://www.haskell.org/pipermail/haskell/2002-January/008677.html unfortunately we never followed up on that promise :-) Looks like it shouldn't be too hard - on Windows there's no truncate(), but there is SetEndOfFile() instead. Cheers, Simon

On Tue, Jan 04, 2005 at 04:39:50PM -0000, Simon Marlow wrote:
There are System.Posix.setFileSize and System.Posix.setFdSize, which are direct interfaces to truncate(2) and ftruncate(2) respectively.
Thanks, Simon. I have no idea how I missed that. It's exactly what I am looking for. -- John

--- Simon Marlow
I seem to recall there was a proposal to add hSetFileSize at one point... ah yes:
http://www.haskell.org/pipermail/haskell/2002-January/008677.html
unfortunately we never followed up on that promise :-) Looks like it shouldn't be too hard - on Windows there's no truncate(), but there is SetEndOfFile() instead.
Under Windows there is also _chsize function from MSVCRT. It is easy to define hSetFileSize function. I also would like to have some functions for creation of temporary files. My proposal is: openTempFile :: FilePath -> String -> IO (FilePath, Handle) openBinaryTempFile :: ... The first argument is the directory where to create the file and the second argument is the file name template. The template is something like "foo.bar" with this template the name of the created file will be fooXXX.bar where XXX is some random number. The function should create immediatelly the file in order to prevent other processes to create a file with the same name. The returned path is the complete path to the created file and the handle is the handle to the created file. Cheers, Krasimir __________________________________ Do you Yahoo!? Read only the mail you want - Yahoo! Mail SpamGuard. http://promotions.yahoo.com/new_mail
participants (3)
-
John Goerzen
-
Krasimir Angelov
-
Simon Marlow