Skip to content

FileRead

Description

Read up to n bytes into buf. Short reads are normal at EOF and on signal interruption (we don’t retry on EINTR for you – callers that need that should loop). Sets the at_eof flag when the syscall reports zero bytes.

Success

Returns the number of bytes read (>= 0).

Failure

Returns -1 on error.

Usage example (Cross-references)

Usage examples (Cross-references)
                return false;
            }
            i64 n = FileRead(&f, out->raw.data + out->raw.length, CHUNK);
            if (n < 0) {
                LOG_ERROR("ProcMapsLoad: FileRead failed");
            i64 n = FileRead(&f, out->raw.data + out->raw.length, CHUNK);
            if (n < 0) {
                LOG_ERROR("ProcMapsLoad: FileRead failed");
                FileClose(&f);
                ProcMapsDeinit(out);
            LOG_INFO("Reading from non-seekable channel.");
            char buf_byte = 0;
            while (FileRead(file, &buf_byte, 1) == 1) {
                StrPushBack(&buffer, buf_byte);
            }
            if (file_len > 0) {
                StrReserve(&buffer, (u64)file_len);
                i64 got = FileRead(file, buffer.data, (u64)file_len);
                if (got < 0) {
                    LOG_ERROR("FileRead failed during f_read_fmt");
                i64 got = FileRead(file, buffer.data, (u64)file_len);
                if (got < 0) {
                    LOG_ERROR("FileRead failed during f_read_fmt");
                    StrDeinit(&buffer);
                    DefaultAllocatorDeinit(&scratch);
    // ---------------------------------------------------------------------------
    
    i64 FileRead(File *f, void *buf, u64 n) {
        if (!FileIsValid(f) || !buf) {
            return -1;
        }
    
        i64 got = FileRead(&f, buffer, (u64)fsize);
        FileClose(&f);
        if (got != fsize) {
Last updated on