dmi_file_load

Synopsis

#include <opendmi/utils.h>

bool dmi_file_load(
        dmi_buffer_t *buffer,
        const char   *path,
        off_t         offset,
        size_t        length);

Description

The dmi_file_load function opens the file at path and reads its contents into buffer, which is made to hold exactly the bytes read: fewer than requested, when the file holds fewer.

The data the buffer held before is dropped, and so is whatever has been read when the reading fails.

This is what the backends reading a table or an entry point out of a file fill the buffer they are given with, see dmi_backend_t.

Parameters

buffer

Buffer to read the contents into.

path

Path to the file to read.

offset

Offset to read from, or a negative value to read from the beginning of the file.

length

Maximum number of bytes to read, or zero to read the whole file.

Return value

true on success, false otherwise.

Errors

DMI_ERROR_ARGUMENT_NULL

Path is nullptr.

DMI_ERROR_FILE_OPEN_FAILED

File cannot be opened.

DMI_ERROR_FILE_STAT_FAILED

Length of the file cannot be told.

DMI_ERROR_FILE_READ_FAILED

File cannot be read.

DMI_ERROR_OUT_OF_MEMORY

Buffer cannot hold the data.

Notes

Errors are raised on the context of the buffer, see dmi_buffer_context.