FReadFmtInternal

Table of Contents

FReadFmtInternal

Description

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

Parameters

NameDirectionDescription
streaminFILE* we’re reading from.
fmtstrinFormat string to be used for reading. This must exactly describe input format.
argvinArray of TypeSpecificIO structures describing where to read for each corresponding placeholder.
argcinNumber of TypeSpecificIO values in array.

Success

Compares fmtstr with stream of characters in stream and reads values at placeholders. A valid value will be stored in . arg provided.

Failure

Logs out error message and returns. If rollback is possible, then un-reads all the read data. Restoring original state. Method can also abort if something really unexpected is encountered. Returns NULL if format string does not match with input stream.

Usage example (Cross-references)

    }
    
    void FReadFmtInternal(FILE *file, const char *fmtstr, TypeSpecificIO *argv, u64 argc) {
    if (!file || !fmtstr) {
    LOG_FATAL("Invalid arguments");
    TypeSpecificIO *argv_ = &(varr)[0];                                                                            \
    u64             argc_ = sizeof(varr) / sizeof(TypeSpecificIO) - 1;                                             \
    FReadFmtInternal((file), (fmtstr), argv_, argc_);                                                              \
    } while (0)

Share :

Related Posts

void

void Description Type-specific write callback signature

Read More

StrWriteFmtInternal

StrWriteFmtInternal Description Print out a formatted string with rust-style placeholders to given string o.

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