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++ 3.0r4 - <b>filelength</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
filelength

Usage

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

Description

   filelength 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 is used on
   a file that is already open.

Example 

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

   int main(int argc, *argv[])

   {
       int fd;
       long l;

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

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

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


       if (close(fd) == -1) {
           perror("Error closing file");
           return EXIT_FAILURE;
       }
       return EXIT_SUCCESS;
   }

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



See Also: filesize

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