Skip to content

FileIsEof

Description

Check whether a previous FileRead reported end-of-file.

Success

Returns true when the last read returned 0 bytes.

Failure

Returns false otherwise. Cannot fail.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    bool FileIsEof(const File *f) {
        return f && f->at_eof;
    }
        // A zero-byte request returns 0 and must NOT flag eof.
        char scratch[4] = {0};
        ok              = ok && (FileRead(&f, scratch, 0) == 0) && !FileIsEof(&f);
    
        // Drain the 2 bytes of content.
    
        // Drain the 2 bytes of content.
        ok = ok && (FileRead(&f, scratch, 2) == 2) && !FileIsEof(&f);
    
        // The next read hits EOF: 0 bytes, eof flag set.
    
        // The next read hits EOF: 0 bytes, eof flag set.
        ok = ok && (FileRead(&f, scratch, 2) == 0) && FileIsEof(&f);
    
        FileClose(&f);
        ok          = ok && FileIsOpen(&f);
        char buf[4] = {0};
        ok          = ok && (FileRead(&f, buf, 2) == 2) && !FileIsEof(&f);
        // The next read hits EOF: 0 bytes and at_eof becomes true.
        ok = ok && (FileRead(&f, buf, 2) == 0) && FileIsEof(&f);
        ok          = ok && (FileRead(&f, buf, 2) == 2) && !FileIsEof(&f);
        // The next read hits EOF: 0 bytes and at_eof becomes true.
        ok = ok && (FileRead(&f, buf, 2) == 0) && FileIsEof(&f);
        FileClose(&f);
        // Drain to EOF to set at_eof.
        ok = ok && (FileRead(&f, buf, 6) == 6);
        ok = ok && (FileRead(&f, buf, 2) == 0) && FileIsEof(&f);
    
        // Seek back to start: returns offset 0 and clears the eof flag.
        // Seek back to start: returns offset 0 and clears the eof flag.
        ok = ok && (FileSeek(&f, 0, FILE_SEEK_SET) == 0);
        ok = ok && !FileIsEof(&f);
        // And reading now succeeds again from the top.
        char buf2[3] = {0};
Last updated on