Skip to content

ZstrIOArg

Description

Explicit raw C-string I/O descriptor with allocator provenance.

This is used when a formatted I/O call needs to read into or rewrite a caller-owned zero-terminated string pointer whose storage may already be managed by a specific allocator.

Parameters

Name Direction Description
value in,out Address of the char * / Zstr variable.
allocator in Allocator responsible for any existing pointed-to storage.

Usage example (Cross-references)

Usage examples (Cross-references)
        void      *value;
        Allocator *allocator;
    } ZstrIOArg;
    
    #ifdef __cplusplus
    #ifdef __cplusplus
    #    define ZstrIO(zstr, alloc_ptr)                                                                                    \
            TO_TYPE_SPECIFIC_IO(ZstrAlloc, &LVAL(((ZstrIOArg) {.value = (void *)&(zstr), .allocator = (alloc_ptr)})))
    #else
    #    define ZstrIO(zstr, alloc_ptr)                                                                                    \
                .writer = (TypeSpecificWriter)_write_ZstrAlloc,                                                            \
                .reader = (TypeSpecificReader)_read_ZstrAlloc,                                                             \
                .data   = &((ZstrIOArg) {.value = (void *)&(zstr), .allocator = (alloc_ptr)}),                             \
            })
    #endif
    bool _write_i64(Str *o, FmtInfo *fmt_info, i64 *v);
    bool _write_Zstr(Str *o, FmtInfo *fmt_info, Zstr *s);
    bool _write_ZstrAlloc(Str *o, FmtInfo *fmt_info, ZstrIOArg *arg);
    bool _write_f32(Str *o, FmtInfo *fmt_info, f32 *v);
    bool _write_f64(Str *o, FmtInfo *fmt_info, f64 *v);
    Zstr _read_i64(Zstr i, FmtInfo *fmt_info, i64 *v);
    Zstr _read_Zstr(Zstr i, FmtInfo *fmt_info, Zstr *v);
    Zstr _read_ZstrAlloc(Zstr i, FmtInfo *fmt_info, ZstrIOArg *arg);
    Zstr _read_f32(Zstr i, FmtInfo *fmt_info, f32 *v);
    Zstr _read_f64(Zstr i, FmtInfo *fmt_info, f64 *v);
    }
    
    bool _write_ZstrAlloc(Str *o, FmtInfo *fmt_info, ZstrIOArg *arg) {
        Zstr *value = NULL;
    }
    
    Zstr _read_ZstrAlloc(Zstr i, FmtInfo *fmt_info, ZstrIOArg *arg) {
        char     **out           = NULL;
        char      *previous      = NULL;
    
        char     *out = NULL;
        ZstrIOArg arg = {.value = (void *)&out, .allocator = alloc_base};
        FmtInfo   fmt = {0}; // max_read_len == 0 -> hits the !max_read_len branch
    
        char     *out = NULL;
        ZstrIOArg arg = {.value = (void *)&out, .allocator = alloc_base};
    
        Zstr next = _read_ZstrAlloc(input, NULL, &arg);
Last updated on