Skip to content
ReadCompleteFileEx

ReadCompleteFileEx

Description

Read complete contents of a file at once.

This API supports two forms:

  • ReadCompleteFile(filename, data, file_size, capacity)
  • ReadCompleteFile(filename, data, file_size, capacity, allocator)

If *data == NULL and no allocator is supplied, DefaultAllocator() is used. If *data == NULL and an allocator is supplied, that allocator is used. If *data != NULL, the allocator responsible for that buffer must be supplied. Omitting it in that case is a caller contract violation.

The returned buffer is null-terminated for convenience.

Parameters

Name Direction Description
filename in Name/path of file to be read.
data in,out Memory buffer where loaded file will be stored.
file_size out Complete size of file in bytes will be stored here.
capacity in,out Current capacity of *data, updated on successful growth.
allocator in,out Optional allocator responsible for *data.

Success

true

Failure

false

Usage example (Cross-references)

Usage examples (Cross-references)
    #include <Misra/Types.h>
    
    bool ReadCompleteFileEx(
        const char *filename,
        char      **data,
    #define ReadCompleteFile(...) CONCAT(ReadCompleteFile_, READ_COMPLETE_FILE_HAS_ARGS(__VA_ARGS__))(__VA_ARGS__)
    #define ReadCompleteFile_4(filename, data, file_size, capacity)                                                         \
        ReadCompleteFileEx((filename), (data), (file_size), (capacity), NULL)
    #define ReadCompleteFile_5(filename, data, file_size, capacity, allocator)                                              \
        ReadCompleteFileEx((filename), (data), (file_size), (capacity), (allocator))
        ReadCompleteFileEx((filename), (data), (file_size), (capacity), NULL)
    #define ReadCompleteFile_5(filename, data, file_size, capacity, allocator)                                              \
        ReadCompleteFileEx((filename), (data), (file_size), (capacity), (allocator))
    
    #endif // MISRA_FILE_H
Last updated on