[Previous]
[Contents]
[Next]

filelength()

return the number of bytes in an open file

Synopsis:

#include <unistd.h>
long int filelength( int filedes );

Description:

The filelength() function returns the number of bytes in the opened file indicated by the file descriptor filedes.

Returns:

The number of bytes in the file. If an error occurs, (-1L) is returned, and errno indicates the type of error detected.

Examples:

#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

Classification:

WATCOM

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

errno, fstat(), lseek(), tell()


[Previous]
[Contents]
[Next]