Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ eof(DOS) — OpenDesktop Software Development System 1.0.0d

Media Vault

Software Library

Restoration Projects

Artifacts Sought

     Name
          eof - Determines end-of-file.

     Syntax
          #include <io.h>

          int eof(handle)
          int handle;

     Description
          The eof function determines whether the end-of-file has been
          reached for the file associated with handle.

     Return Value
          The eof function returns the value 1 if the current position
          is end-of-file, or 0 if it is not. A return value of -1
          indicates an error; in this case, errno is set to EBADF,
          indicating an invalid file handle.

     See Also
          clearerr(S), feof(S), ferror(S), perror(S)

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

          int fh, count; char buf[10]; main( )
            {
                  int total = 0;

                  fh = open("data",O_RDONLY);

                  /* Cycle until end of file reached: */
                  while (!eof(fh))
                  {
                          /* Attempt to read in 10 bytes: */

                          if ((count = read(fh, buf, 10)) == -1)
                          {
                                  perror("Read error; invalid file
          handle");
                                  break;
                          }
                          /* Total up actual bytes read */
                          total += count;
                  }
                  printf("Number of bytes read = %d\n", total);
           }

          This program opens a file named data and reads data from the
          file until the end of the file is reached. It then uses the
          eof function to determine when the end of the file was
          found. If the read function reports an error, reading is
          terminated and the current total is reported.

                                                (printed 6/18/89)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026