Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ Language Reference - filelength http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
   filelength

   Usage
   #include <io.h>
   long filelength(int fd);

   Description
   fileno  returns  the length in bytes of the file associated  with  the
   file  descriptor  fd. The fd argument must point to a  file  which  is
   already open.

   The  filelength function differs from filesize in that it can be  used
   on a file which is already open.

   Example
   #include <stdio.h>
   #include <io.h>
   #include <fcntl.h>

   main(argc,argv)
   int argc;
   char *argv[];
   {
   int fd;
   long l;

        if(argc < 2)
        {
             printf("Usage: fl 'filename'\n");
             exit(1);
        }

        fd = open(argv[1],O_RDONLY,0);
        if(fd == -1)
        {
             perror("Error opening file");
             exit(1);
        }
        l = filelength(fd);

        printf("File %s is %ld bytes long\n",argv[1],l);

        if(close(fd) == -1);
             perror("Error closing file");

        return 0;
   }

   Return Value
   filelength returns the length of the file in bytes as a long  integer.
   The current read/write position within the file is unaltered.


See Also: filesize

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson