FReadFmt

Table of Contents

FReadFmt

Description

Read formatted data from a file stream. This is a macro wrapper around FReadFmtInternal.

Parameters

NameDirectionDescription
streaminPointer to the FILE stream to read from.
fmtstrinFormat string to be used for reading. This must exactly describe the expected input format in the stream. argument should be a modifiable l-value wrapped with &variable.

Success

Attempts to match fmtstr with the stream of characters in stream and reads values into the provided arguments wrapped with ``.

Failure

Failure occurs within FReadFmtInternal. Refer to its documentation for details on failure behavior (logs error message and returns, may rollback read data, or abort in unexpected situations).

Usage example (Cross-references)

    
    ElfHeader64 eh = {0};
    FReadFmt(elf, FMT_ELF_META, eh.meta.class, eh.meta.encoding, eh.meta.version, eh.meta.os_abi, eh.meta.abi_version);
    
    // technically padding here but we can skip it
    }
    
    FReadFmt(
    elf,
    eh.meta.encoding == ELF_ENCODING_LSB ? FMT_ELF_HEADER_64_LE : FMT_ELF_HEADER_64_BE,
    /// TAGS: Macro, Convenience, Stdin, I/O
    ///
    #define ReadFmt(...) FReadFmt(stdin, __VA_ARGS__)
    
    // not for direct use

Share :

Related Posts

StrReadFmt

StrReadFmt Description Parse input string according to format string with rust-style placeholders, extracting values into provided arguments. This is a macro wrapper around StrReadFmtInternal.

Read More

ReadCompleteFile

ReadCompleteFile Description Read complete contents of file at once. Pointer returned is malloc’d and hence must be freed after use. The returned pointer can also be reused by providing pointer to it in data parameter. realloc is called on *data in order to expand it’s size. If *capacity exceeds the size of file to be loaded, then no reallocation is performed. This means the provided buffer will automatically be expanded if required. The returned buffer is null-terminated just-in-case. The implementation and API is designed in such a way that it can be used with containers like Vec and Str.

Read More

FReadFmtInternal

FReadFmtInternal Description Read formatted data from file streams (stdin, or other file)

Read More