ファイルサイズを取得し、ファイルサイズを変更する
ファイルサイズを取得する関数はCの標準にあるのかないのか良く分からん・・・。
// crt_chsize.c // This program uses _filelength to report the size // of a file before and after modifying it with _chsize. #include <io.h> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> #include <stdio.h> #include <share.h> int main( void ) { int fh, result; unsigned int nbytes = BUFSIZ; // Open a file if( _sopen_s( &fh, "data", _O_RDWR | _O_CREAT, _SH_DENYNO, _S_IREAD | _S_IWRITE ) == 0 ) { printf( "File length before: %ld\n", _filelength( fh ) ); if( ( result = _chsize( fh, 329678 ) ) == 0 ) printf( "Size successfully changed\n" ); else printf( "Problem in changing the size\n" ); printf( "File length after: %ld\n", _filelength( fh ) ); _close( fh ); } }