This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
the file truncate API is limited and inconvenient
- From: Krzysztof Åelechowski <giecrilj at stegny dot 2a dot pl>
- To: libc-help at sourceware dot org
- Date: Thu, 6 May 2010 20:43:39 +0200
- Subject: the file truncate API is limited and inconvenient
I am reading the description of the file truncate API at "14.9.10 File Size"
[1]:
:However, sometimes it is necessary to reduce the size of a file. This can be
done with the truncate and ftruncate functions. They were introduced in BSD
Unix. ftruncate was later added to POSIX.1.
1. How is it possible that they were not needed before BSD UNIX?
2. It is obvious for me that there should be a stdio API with the meaning "let
here be the end of this FILE". I can do this under POSIX by using ftruncate
but it requires writing my own subroutine (ftuncate (fileno (), ftell())), and
of course there is no C++ way to do this. How is it possible that nobody ever
needed this to be a standard API?
I understand that you can end a text file with ^Z (which is because at IBM
file size had to be a multiple of 128) and that binary formats can just ignore
excessive data. However, disk space was very expensive those days, so wasting
it for unneeded data would not be very wise IMHO, and the alternative of
copying the file can run out of disk space when the data part is big enough.
Please enlighten me on the subject.
Astonished,
Chris
== References ==
[1] <URL:http://www.gnu.org/software/libc/manual/html_node/File-
Size.html#File-Size>