Allocate space for a file on the filesystem
#include <fcntl.h> int posix_fallocate( int fd, off_t offset, off_t len ); int posix_fallocate64( int fd, off64_t offset, off64_t len );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The posix_fallocate() and posix_fallocate64() functions ensure that any required storage for regular file data starting at offset and continuing for len bytes is allocated on the filesystem storage media. The posix_fallocate64() function is a large-file support version of posix_fallocate().
If posix_fallocate() returns successfully, subsequent writes to the specified file data won't fail due to the lack of free space on the filesystem storage media.
If the offset + len is beyond the current file size, then posix_fallocate() adjusts the file size to be offset + len. Otherwise, the file size isn't changed.
You can free the allocated space by using creat() or open() to truncate the file, or by calling ftruncate() to make the size of the file less than offset + len.
posix_fallocate() is POSIX 1003.1 ADV; posix_fallocate64() is Large-file support
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |