Missing ftruncate
John Goerzen
jgoerzen at complete.org
Mon Dec 20 17:00:58 EST 2004
Hi,
There appears to be no interface in Haskell to ftruncate(2). (Or, for
that matter, the less-useful truncate(2)).
For those that don't know, ftruncate(2) is frequently used to remove
data at the end of an open file when that data is no longer needed.
According to my Linux ftruncate(2) manpage:
int truncate(const char *path, off_t length);
int ftruncate(int fd, off_t length);
...
CONFORMING TO
4.4BSD, SVr4 (these function calls first appeared in BSD 4.2). POSIX
1003.1-1996 has ftruncate. POSIX 1003.1-2001 also has truncate, as an
XSI extension.
I found this in fptools' libraries/base/System/Posix/Internals.hs:
-- It isn't clear whether ftruncate is POSIX or not (I've read several
-- manpages and they seem to conflict), so we truncate using open/2.
fileTruncate :: FilePath -> IO ()
There are several problems with this:
1. System.Posix.Internals doesn't appear to be an exposed, documented
API
2. There is no way to specify a length
3. There is no interface to ftruncate().
4. If the manpages do conflict, a read of the standard should clarify
it. In any case, ftruncate() appears to have been around for a LONG
time.
Would it be possible to provide a Haskell interface to ftruncate() at
least? (truncate() can always be implemented in terms of it.)
Thanks,
John
More information about the Libraries
mailing list