Gets the length of a file.
#include <io.h> | Required only for function declarations |
long _filelength(inthandle );
handle | Target file handle |
The _filelength function returns the length, in bytes, of the target file associated with handle.
The _filelength function returns the file length in bytes. A return value of –1L indicates an error, and an invalid handle sets errno to EBADF.
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:DOS32X
_chsize, _fileno, _fstat, _stat
/* 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>
void main( void )
{
int fh, result;
unsigned int nbytes = BUFSIZ;
/* Open a file */
if( (fh = _open( "data", _O_RDWR | _O_CREAT,
_S_IREAD | _S_IWRITE )) != -1 )
{
printf( "File length before: %ld\n", _filelength( fh ) );
if( _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 );
}
}
File length before: 0
Size successfully changed
File length after: 329678