Skip to content

FileFromFd

Description

Borrow a file handle wrapping an already-open fd / HANDLE. The returned File has owns = false so FileClose is a no-op on it. Use for wrapping stdin / stdout / stderr or fds you got from elsewhere.

Usage example (Cross-references)

Usage examples (Cross-references)
        StrWriteFmt(&full, "[{}] [{}:{}] {}\n", (const char *)NAMES[type], (const char *)tag, line, (const char *)msg);
    
        File out = (type == LOG_MESSAGE_TYPE_INFO) ? FileFromFd(1) : FileFromFd(2);
        (void)FileWrite(&out, full.data, full.length);
    }
    
    File FileFromFd(i32 fd) {
        File f = {0};
    #ifdef _WIN32
        return f;
    #else
        return FileFromFd(0);
    #endif
    }
        return f;
    #else
        return FileFromFd(1);
    #endif
    }
        return f;
    #else
        return FileFromFd(2);
    #endif
    }
Last updated on