return the number of bytes in an open file
#include <unistd.h> long int filelength( int filedes );
The filelength() function returns the number of bytes in the opened file indicated by the file descriptor filedes.
The number of bytes in the file. If an error occurs, (-1L) is returned, and errno indicates the type of error detected.
#include <sys/types.h> #include <fcntl.h> #include <stdio.h> #include <unistd.h> void main() { int filedes ; /* open a file for input */ filedes = open( "file", O_RDONLY ); if( filedes != -1 ) { printf( "Size of file is %ld bytes\n", filelength( filedes ) ); close( filedes ); } }
produces the output:
Size of file is 461 bytes
WATCOM
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
errno, fstat(), lseek(), tell()