This works only on MS-DOG (that needs an lseek and a one-byte write to
extend files anyway). Linux will not allocate blocks immediatelly on
ftruncate. It will pretend that these unallocated holes are all-'\0' and
sets the remainder of a block to 0 when you do try to write it.
Did anyone check NT?
> So its not portable.
>
> True. From various other messages I have recieved and from notes in
> /usr/src/linux/mm/mmap.c there are a lot of nonportable things going
> on.
>
It's semi-portable. POSIX 4 specifies that ftruncate can expand shared
memory objects and it would be real bogus for a modern OS to implement it
differently on files. But anyway, it's pretty easy to write a function that
tries to expand a file with ftruncate one time and if it doesn't work switches
to lseek+1 byte write.
-- _. _ . (_ ,_ _ , . / ` _ _L | Email: Oleg Kibirev <snowcat@netgate.net> ._)| U(_)\/\/ \_,(_L/L | Visit http://math.math.CSUFresno.EDU/~oleg/math.html ------------------------' to get my programs + PGP public key