change the size of a file
#include <unistd.h> int chsize( int filedes, long size );
The chsize() function changes the size of the file associated with filedes, by extending or truncating the file to the length specified by size. If the file needs to be extended, the file is padded with NULL ('\0') characters.
The chsize() function call ignores advisory locks that may have been set by the fcntl(), lock(), or locking() functions. |
#include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <sys/stat.h> void main() { int filedes; filedes= open( "file", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP ); if( filedes!= -1 ) { if( chsize( filedes, 32 * 1024L ) != 0 ) { printf( "Error extending file\n" ); } close( filedes); } }
WATCOM
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes, but modifies errno |
Thread | Yes |
close(), creat(), errno, open()