I need a function which will create a file with fixed size in linux. Function like truncate or fopen,fseek,fclose, is not a solution because, they will fill opened file with zeros, but it is not necessary and I have no time for this. So is there some function, which will only open a file with fixed length and not fill buffer?
Thanks in advance.
The system call
truncate(2)doesn’t fill the file with zeros. It simply advances the file’s reported size and leaves holes in it.When you read from it, you do get zeros, but that’s just a convenience of the OS.
About holes (from TLPI):
Filesystems and holes:
As Per Johansson notes, this is dependent of the filesystem.