Skip to content

FileIsOpen

Description

True if the underlying handle is currently open.

Usage example (Cross-references)

Usage examples (Cross-references)
        // (no libc fopen/fwrite/fclose).
        File f = FileOpen(path, "w");
        if (!FileIsOpen(&f))
            return false;
        bool ok = (u64)FileWrite(&f, data, size) == size;
    static bool write_file(const char *path, const u8 *data, u64 size) {
        File f = FileOpen(path, "wb");
        if (!FileIsOpen(&f))
            return false;
        bool ok = FileWrite(&f, data, size) == (i64)size;
    static bool write_test_file(const char *text, Str *out_path, Allocator *alloc) {
        File f = FileOpenTemp(out_path, alloc);
        if (!FileIsOpen(&f)) {
            return false;
        }
    
        File f = FileOpen(&path, "rb");
        if (!FileIsOpen(&f)) {
            FileRemove(&path);
            StrDeinit(&path);
    
        File f = FileOpen(&path, "rb");
        if (!FileIsOpen(&f)) {
            FileRemove(&path);
            StrDeinit(&path);
    static bool path_exists(const char *path) {
        File f = FileOpen(path, "rb");
        if (!FileIsOpen(&f)) {
            return false;
        }
    static bool slurp_file(const char *path, Str *out) {
        File f = FileOpen(path, "rb");
        if (!FileIsOpen(&f)) {
            // Missing config file is fine -- resolver just won't know about it.
            return true;
    static bool path_exists(const char *path) {
        File f = FileOpen(path, "rb");
        if (!FileIsOpen(&f)) {
            return false;
        }
    static bool path_exists(const char *path) {
        File f = FileOpen(path, "rb");
        if (!FileIsOpen(&f)) {
            return false;
        }
        // empty -- we have to loop-read into a growing buffer ourselves.
        File f = FileOpen("/proc/self/maps", "rb");
        if (!FileIsOpen(&f)) {
            LOG_ERROR("ProcMapsLoad: FileOpen(/proc/self/maps) failed");
            ProcMapsDeinit(out);
    }
    
    bool FileIsOpen(const File *f) {
        if (!f) {
            return false;
    
    i64 file_read(File *f, void *buf, u64 n) {
        if (!FileIsOpen(f) || !buf) {
            return -1;
        }
    
    i64 FileWrite(File *f, const void *buf, u64 n) {
        if (!FileIsOpen(f) || !buf) {
            return -1;
        }
    
    i64 FileSeek(File *f, i64 offset, FileWhence whence) {
        if (!FileIsOpen(f)) {
            return -1;
        }
    
    bool FileFlush(File *f) {
        if (!FileIsOpen(f)) {
            return false;
        }
Last updated on