Skip to content

Zstr

Description

Read-only NUL-terminated C string – the project name for a const char *. Zstr is the canonical C-string type in the codebase for declarations, parameters, return types, and fields. -Wwrite-strings (gcc/clang) types string literals as const char * (= Zstr) and rejects char *p = "literal".

_Generic dispatch has one carve-out: every arm matching Zstr also has a char * synonym arm with the same body. MSVC’s C _Generic follows the C standard, which types string literals as char[N] decaying to char *; /Zc:strictStrings is a C++-only flag with no effect in C mode. Inlining both arms at every dispatch site is what keeps the codebase portable to MSVC. See CODING-CONVENTIONS.md for the canonical shape.

Cstr is not a type but a naming-suffix for the (Zstr, size) form – a non-NUL-terminated view, or a NUL-terminated string truncated at an explicit length. See StrStartsWith for the canonical Cstr / Zstr / unsuffixed-Str overload family.

Usage example (Cross-references)

Usage examples (Cross-references)
    #include <Misra/Std/Prng.h>
    #include <Misra/Std/Utility.h>
    #include <Misra/Std/Zstr.h>
    
    #if FEATURE_ALLOC_ARENA
    /// canonical Cstr / Zstr / unsuffixed-Str overload family.
    typedef const char *Zstr;
    typedef Vec(Zstr) Zstrs;
    
    ///
    ///
    /// TAGS: Zstr, Length
    size ZstrLen(Zstr str);
    
    ///
    ///
    /// TAGS: Zstr, Comparison
    i32 ZstrCompare(Zstr s1, Zstr s2);
    
    ///
    /// TAGS: Zstr, Hash, Ops
    ///
    u64 zstr_hash(const Zstr *key, u32 size);
    
    ///
    /// TAGS: Zstr, Compare, Ops
    ///
    i32 zstr_compare(const Zstr *a, const Zstr *b, u32 size);
    
    ///
    ///
    /// TAGS: Zstr, Comparison
    i32 ZstrCompareN(Zstr s1, Zstr s2, size n);
    
    ///
    ///
    /// TAGS: Zstr, Comparison, IgnoreCase
    i32 ZstrCompareIgnoreCase(Zstr s1, Zstr s2);
    
    ///
    ///
    /// TAGS: Zstr, Comparison, IgnoreCase
    i32 ZstrCompareNIgnoreCase(Zstr s1, Zstr s2, size n);
    
    ///
    ///
    /// TAGS: Zstr, Search
    Zstr ZstrFindChar(Zstr str, char ch);
    
    ///
    ///
    /// TAGS: Zstr, Search
    Zstr ZstrFindSubstring(Zstr haystack, Zstr needle);
    
    ///
    ///
    /// TAGS: Zstr, Search
    Zstr ZstrFindSubstringN(Zstr haystack, Zstr needle, size needle_len);
    
    ///
    ///
    /// TAGS: Zstr, Allocation
    Zstr zstr_dup_n(Zstr src, size n, Allocator *alloc);
    #define ZstrDupN(...)             OVERLOAD(ZstrDupN, __VA_ARGS__)
    #define ZstrDupN_2(src, n)        zstr_dup_n((src), (n), MisraScope)
    ///
    /// TAGS: Zstr, Allocation
    Zstr zstr_dup(Zstr src, Allocator *alloc);
    #define ZstrDup(...)          OVERLOAD(ZstrDup, __VA_ARGS__)
    #define ZstrDup_1(src)        zstr_dup((src), MisraScope)
    ///
    /// TAGS: Zstr, Parse, Escape
    char ZstrProcessEscape(Zstr *str);
    
    ///
    ///
    /// TAGS: Zstr, Parse, Integer
    i64 ZstrToI64(Zstr s, Zstr *endptr);
    
    ///
    ///
    /// TAGS: Zstr, Parse, Float
    f64 ZstrToF64(Zstr s, Zstr *endptr);
    
    #endif // MISRA_STD_ZSTR_H
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/File.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
        typedef enum ArgKind {
            ARG_KIND_INVALID = 0, // unknown target type -- registration fails
            ARG_KIND_ZSTR,        // `Zstr *` / `char **`
            ARG_KIND_STR,         // `Str *`
            ARG_KIND_BOOL,        // `bool *`
        ///
        typedef struct ArgSpec {
            Zstr    short_name; // "-l" or NULL; ignored for positionals
            Zstr    long_name;  // "--listen" for options; metavar (e.g. "hostname") for positionals
            Zstr    help;       // one-line description for `--help`
        typedef struct ArgSpec {
            Zstr    short_name; // "-l" or NULL; ignored for positionals
            Zstr    long_name;  // "--listen" for options; metavar (e.g. "hostname") for positionals
            Zstr    help;       // one-line description for `--help`
            ArgRole role;
            Zstr    short_name; // "-l" or NULL; ignored for positionals
            Zstr    long_name;  // "--listen" for options; metavar (e.g. "hostname") for positionals
            Zstr    help;       // one-line description for `--help`
            ArgRole role;
            ArgKind kind;
        typedef struct ArgParse {
            Allocator *alloc;
            Zstr       name;
            Zstr       about;
            ArgSpecs   specs;
            Allocator *alloc;
            Zstr       name;
            Zstr       about;
            ArgSpecs   specs;
            File      *out;
        /// TAGS: ArgParse, Register, Internal
        ///
        void arg_register(ArgParse *self, ArgRole role, Zstr short_name, Zstr long_name, Zstr help, ArgTarget target);
    
        ///
        _Generic(                                                                                                          \
            (t),                                                                                                           \
            Zstr *: ((ArgTarget) {ARG_KIND_ZSTR, (void *)(t)}),                                                            \
            char **: ((ArgTarget) {ARG_KIND_ZSTR, (void *)(t)}),                                                           \
            Str *: ((ArgTarget) {ARG_KIND_STR, (void *)(t)}),                                                              \
    #include <Misra/Std/Container/Buf.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
    /// TAGS: File, Open, API
    ///
    File file_open(Zstr path, Zstr mode);
    #define FileOpen(path, mode)                                                                                           \
        _Generic(                                                                                                          \
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: file_open((Zstr)StrBegin((Str *)(path)), (mode)),                                                       \
            Zstr: file_open((Zstr)(path), (mode)),                                                                         \
            char *: file_open((Zstr)(path), (mode))                                                                        \
            (path),                                                                                                        \
            Str *: file_open((Zstr)StrBegin((Str *)(path)), (mode)),                                                       \
            Zstr: file_open((Zstr)(path), (mode)),                                                                         \
            char *: file_open((Zstr)(path), (mode))                                                                        \
        )
            Str *: file_open((Zstr)StrBegin((Str *)(path)), (mode)),                                                       \
            Zstr: file_open((Zstr)(path), (mode)),                                                                         \
            char *: file_open((Zstr)(path), (mode))                                                                        \
        )
    /// TAGS: File, Read
    ///
    i64 file_read_and_close_to_buf(Zstr path, Buf *out);
    i64 file_read_and_close_to_str(Zstr path, Str *out);
    #define FileReadAndClose(path, out)                                                                                    \
    ///
    i64 file_read_and_close_to_buf(Zstr path, Buf *out);
    i64 file_read_and_close_to_str(Zstr path, Str *out);
    #define FileReadAndClose(path, out)                                                                                    \
        _Generic(                                                                                                          \
            Buf *: _Generic(                                                                                               \
                     (path),                                                                                               \
                    Str *: file_read_and_close_to_buf((Zstr)StrBegin((Str *)(path)), (Buf *)(out)),                        \
                    Zstr: file_read_and_close_to_buf((Zstr)(path), (Buf *)(out)),                                          \
                    char *: file_read_and_close_to_buf((Zstr)(path), (Buf *)(out))                                         \
                     (path),                                                                                               \
                    Str *: file_read_and_close_to_buf((Zstr)StrBegin((Str *)(path)), (Buf *)(out)),                        \
                    Zstr: file_read_and_close_to_buf((Zstr)(path), (Buf *)(out)),                                          \
                    char *: file_read_and_close_to_buf((Zstr)(path), (Buf *)(out))                                         \
                 ),                                                                                                        \
                    Str *: file_read_and_close_to_buf((Zstr)StrBegin((Str *)(path)), (Buf *)(out)),                        \
                    Zstr: file_read_and_close_to_buf((Zstr)(path), (Buf *)(out)),                                          \
                    char *: file_read_and_close_to_buf((Zstr)(path), (Buf *)(out))                                         \
                 ),                                                                                                        \
            Str *: _Generic(                                                                                               \
            Str *: _Generic(                                                                                               \
                     (path),                                                                                               \
                    Str *: file_read_and_close_to_str((Zstr)StrBegin((Str *)(path)), (Str *)(out)),                        \
                    Zstr: file_read_and_close_to_str((Zstr)(path), (Str *)(out)),                                          \
                    char *: file_read_and_close_to_str((Zstr)(path), (Str *)(out))                                         \
                     (path),                                                                                               \
                    Str *: file_read_and_close_to_str((Zstr)StrBegin((Str *)(path)), (Str *)(out)),                        \
                    Zstr: file_read_and_close_to_str((Zstr)(path), (Str *)(out)),                                          \
                    char *: file_read_and_close_to_str((Zstr)(path), (Str *)(out))                                         \
                 )                                                                                                         \
                    Str *: file_read_and_close_to_str((Zstr)StrBegin((Str *)(path)), (Str *)(out)),                        \
                    Zstr: file_read_and_close_to_str((Zstr)(path), (Str *)(out)),                                          \
                    char *: file_read_and_close_to_str((Zstr)(path), (Str *)(out))                                         \
                 )                                                                                                         \
        )
    /// TAGS: File, Write
    ///
    i64 file_write_and_close_from_buf(Zstr path, const Buf *in);
    i64 file_write_and_close_from_str(Zstr path, const Str *in);
    i64 file_write_and_close_from_bytes(Zstr path, const void *buf, u64 n);
    ///
    i64 file_write_and_close_from_buf(Zstr path, const Buf *in);
    i64 file_write_and_close_from_str(Zstr path, const Str *in);
    i64 file_write_and_close_from_bytes(Zstr path, const void *buf, u64 n);
    #define FileWriteAndClose(...) OVERLOAD(FileWriteAndClose, __VA_ARGS__)
    i64 file_write_and_close_from_buf(Zstr path, const Buf *in);
    i64 file_write_and_close_from_str(Zstr path, const Str *in);
    i64 file_write_and_close_from_bytes(Zstr path, const void *buf, u64 n);
    #define FileWriteAndClose(...) OVERLOAD(FileWriteAndClose, __VA_ARGS__)
    #define FileWriteAndClose_2(path, container)                                                                           \
            Buf *: _Generic(                                                                                               \
                     (path),                                                                                               \
                    Str *: file_write_and_close_from_buf((Zstr)StrBegin((Str *)(path)), (const Buf *)(container)),         \
                    Zstr: file_write_and_close_from_buf((Zstr)(path), (const Buf *)(container)),                           \
                    char *: file_write_and_close_from_buf((Zstr)(path), (const Buf *)(container))                          \
                     (path),                                                                                               \
                    Str *: file_write_and_close_from_buf((Zstr)StrBegin((Str *)(path)), (const Buf *)(container)),         \
                    Zstr: file_write_and_close_from_buf((Zstr)(path), (const Buf *)(container)),                           \
                    char *: file_write_and_close_from_buf((Zstr)(path), (const Buf *)(container))                          \
                 ),                                                                                                        \
                    Str *: file_write_and_close_from_buf((Zstr)StrBegin((Str *)(path)), (const Buf *)(container)),         \
                    Zstr: file_write_and_close_from_buf((Zstr)(path), (const Buf *)(container)),                           \
                    char *: file_write_and_close_from_buf((Zstr)(path), (const Buf *)(container))                          \
                 ),                                                                                                        \
            Str *: _Generic(                                                                                               \
            Str *: _Generic(                                                                                               \
                     (path),                                                                                               \
                    Str *: file_write_and_close_from_str((Zstr)StrBegin((Str *)(path)), (const Str *)(container)),         \
                    Zstr: file_write_and_close_from_str((Zstr)(path), (const Str *)(container)),                           \
                    char *: file_write_and_close_from_str((Zstr)(path), (const Str *)(container))                          \
                     (path),                                                                                               \
                    Str *: file_write_and_close_from_str((Zstr)StrBegin((Str *)(path)), (const Str *)(container)),         \
                    Zstr: file_write_and_close_from_str((Zstr)(path), (const Str *)(container)),                           \
                    char *: file_write_and_close_from_str((Zstr)(path), (const Str *)(container))                          \
                 )                                                                                                         \
                    Str *: file_write_and_close_from_str((Zstr)StrBegin((Str *)(path)), (const Str *)(container)),         \
                    Zstr: file_write_and_close_from_str((Zstr)(path), (const Str *)(container)),                           \
                    char *: file_write_and_close_from_str((Zstr)(path), (const Str *)(container))                          \
                 )                                                                                                         \
        )
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: file_write_and_close_from_bytes((Zstr)StrBegin((Str *)(path)), (buf), (n)),                             \
            Zstr: file_write_and_close_from_bytes((Zstr)(path), (buf), (n)),                                               \
            char *: file_write_and_close_from_bytes((Zstr)(path), (buf), (n))                                              \
            (path),                                                                                                        \
            Str *: file_write_and_close_from_bytes((Zstr)StrBegin((Str *)(path)), (buf), (n)),                             \
            Zstr: file_write_and_close_from_bytes((Zstr)(path), (buf), (n)),                                               \
            char *: file_write_and_close_from_bytes((Zstr)(path), (buf), (n))                                              \
        )
            Str *: file_write_and_close_from_bytes((Zstr)StrBegin((Str *)(path)), (buf), (n)),                             \
            Zstr: file_write_and_close_from_bytes((Zstr)(path), (buf), (n)),                                               \
            char *: file_write_and_close_from_bytes((Zstr)(path), (buf), (n))                                              \
        )
    /// TAGS: Log, Write, Diagnostics, Backtrace, IO
    ///
    void LogWrite(LogMessageType type, Zstr tag, u64 line, Zstr msg);
    
    #endif // MISRA_STD_LOG_H
    #include <Misra/Std/Container/Buf.h>
    #include <Misra/Std/DateTime.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/File.h>
    #include <Misra/Types.h>
    /// TAGS: I/O, Callback, Generic
    ///
    typedef Zstr (*TypeSpecificReader)(Zstr i, FmtInfo *fmt_info, void *data);
    
    ///
                DateTime: TO_TYPE_SPECIFIC_IO(DateTime, &(x)),                                                             \
                IOFMT_FLOAT_CASE_(x, &(x)) IOFMT_INT_CASE_(x, &(x)) IOFMT_BITVEC_CASE_(x, &(x)) IOFMT_USER_CASE_(x, &(x))  \
                    Zstr: TO_TYPE_SPECIFIC_IO(Zstr, &(x)),                                                                 \
                char *: TO_TYPE_SPECIFIC_IO(Zstr, &(x)),                                                                   \
                unsigned char: TO_TYPE_SPECIFIC_IO(u8, &(x)),                                                              \
                IOFMT_FLOAT_CASE_(x, &(x)) IOFMT_INT_CASE_(x, &(x)) IOFMT_BITVEC_CASE_(x, &(x)) IOFMT_USER_CASE_(x, &(x))  \
                    Zstr: TO_TYPE_SPECIFIC_IO(Zstr, &(x)),                                                                 \
                char *: TO_TYPE_SPECIFIC_IO(Zstr, &(x)),                                                                   \
                unsigned char: TO_TYPE_SPECIFIC_IO(u8, &(x)),                                                              \
                unsigned short: TO_TYPE_SPECIFIC_IO(u16, &(x)),                                                            \
                DateTime: TO_TYPE_SPECIFIC_IO(DateTime, (void *)&(x)),                                                     \
                IOFMT_FLOAT_CASE_(x, (void *)&(x)) IOFMT_INT_CASE_(x, (void *)&(x)) IOFMT_BITVEC_CASE_(x, (void *)&(x))    \
                    IOFMT_USER_CASE_(x, (void *)&(x)) Zstr: TO_TYPE_SPECIFIC_IO(Zstr, (void *)&(x)),                       \
                char *: TO_TYPE_SPECIFIC_IO(Zstr, (void *)&(x)),                                                           \
                unsigned char: TO_TYPE_SPECIFIC_IO(u8, (void *)&(x)),                                                      \
                IOFMT_FLOAT_CASE_(x, (void *)&(x)) IOFMT_INT_CASE_(x, (void *)&(x)) IOFMT_BITVEC_CASE_(x, (void *)&(x))    \
                    IOFMT_USER_CASE_(x, (void *)&(x)) Zstr: TO_TYPE_SPECIFIC_IO(Zstr, (void *)&(x)),                       \
                char *: TO_TYPE_SPECIFIC_IO(Zstr, (void *)&(x)),                                                           \
                unsigned char: TO_TYPE_SPECIFIC_IO(u8, (void *)&(x)),                                                      \
                unsigned short: TO_TYPE_SPECIFIC_IO(u16, (void *)&(x)),                                                    \
            TypeSpecificIO *UNPL(argv) = &(varr)[0];                                                                       \
            u64             UNPL(argc) = sizeof(varr) / sizeof(TypeSpecificIO);                                            \
            Zstr            UNPL(out)  = str_read_fmt((input), (fmtstr), UNPL(argv), UNPL(argc) - 1);                      \
            if (UNPL(out))                                                                                                 \
                (input) = UNPL(out);                                                                                       \
    bool _write_i32(Str *o, FmtInfo *fmt_info, i32 *v);
    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);
    #endif
    
    Zstr _read_Str(Zstr i, FmtInfo *fmt_info, Str *s);
    Zstr _read_Buf(Zstr i, FmtInfo *fmt_info, Buf *b);
    Zstr _read_DateTime(Zstr i, FmtInfo *fmt_info, DateTime *dt);
    
    Zstr _read_Str(Zstr i, FmtInfo *fmt_info, Str *s);
    Zstr _read_Buf(Zstr i, FmtInfo *fmt_info, Buf *b);
    Zstr _read_DateTime(Zstr i, FmtInfo *fmt_info, DateTime *dt);
    Zstr _read_u8(Zstr i, FmtInfo *fmt_info, u8 *v);
    Zstr _read_Str(Zstr i, FmtInfo *fmt_info, Str *s);
    Zstr _read_Buf(Zstr i, FmtInfo *fmt_info, Buf *b);
    Zstr _read_DateTime(Zstr i, FmtInfo *fmt_info, DateTime *dt);
    Zstr _read_u8(Zstr i, FmtInfo *fmt_info, u8 *v);
    Zstr _read_u16(Zstr i, FmtInfo *fmt_info, u16 *v);
    Zstr _read_Buf(Zstr i, FmtInfo *fmt_info, Buf *b);
    Zstr _read_DateTime(Zstr i, FmtInfo *fmt_info, DateTime *dt);
    Zstr _read_u8(Zstr i, FmtInfo *fmt_info, u8 *v);
    Zstr _read_u16(Zstr i, FmtInfo *fmt_info, u16 *v);
    Zstr _read_u32(Zstr i, FmtInfo *fmt_info, u32 *v);
    Zstr _read_DateTime(Zstr i, FmtInfo *fmt_info, DateTime *dt);
    Zstr _read_u8(Zstr i, FmtInfo *fmt_info, u8 *v);
    Zstr _read_u16(Zstr i, FmtInfo *fmt_info, u16 *v);
    Zstr _read_u32(Zstr i, FmtInfo *fmt_info, u32 *v);
    Zstr _read_u64(Zstr i, FmtInfo *fmt_info, u64 *v);
    Zstr _read_u8(Zstr i, FmtInfo *fmt_info, u8 *v);
    Zstr _read_u16(Zstr i, FmtInfo *fmt_info, u16 *v);
    Zstr _read_u32(Zstr i, FmtInfo *fmt_info, u32 *v);
    Zstr _read_u64(Zstr i, FmtInfo *fmt_info, u64 *v);
    Zstr _read_i8(Zstr i, FmtInfo *fmt_info, i8 *v);
    Zstr _read_u16(Zstr i, FmtInfo *fmt_info, u16 *v);
    Zstr _read_u32(Zstr i, FmtInfo *fmt_info, u32 *v);
    Zstr _read_u64(Zstr i, FmtInfo *fmt_info, u64 *v);
    Zstr _read_i8(Zstr i, FmtInfo *fmt_info, i8 *v);
    Zstr _read_i16(Zstr i, FmtInfo *fmt_info, i16 *v);
    Zstr _read_u32(Zstr i, FmtInfo *fmt_info, u32 *v);
    Zstr _read_u64(Zstr i, FmtInfo *fmt_info, u64 *v);
    Zstr _read_i8(Zstr i, FmtInfo *fmt_info, i8 *v);
    Zstr _read_i16(Zstr i, FmtInfo *fmt_info, i16 *v);
    Zstr _read_i32(Zstr i, FmtInfo *fmt_info, i32 *v);
    Zstr _read_u64(Zstr i, FmtInfo *fmt_info, u64 *v);
    Zstr _read_i8(Zstr i, FmtInfo *fmt_info, i8 *v);
    Zstr _read_i16(Zstr i, FmtInfo *fmt_info, i16 *v);
    Zstr _read_i32(Zstr i, FmtInfo *fmt_info, i32 *v);
    Zstr _read_i64(Zstr i, FmtInfo *fmt_info, i64 *v);
    Zstr _read_i8(Zstr i, FmtInfo *fmt_info, i8 *v);
    Zstr _read_i16(Zstr i, FmtInfo *fmt_info, i16 *v);
    Zstr _read_i32(Zstr i, FmtInfo *fmt_info, i32 *v);
    Zstr _read_i64(Zstr i, FmtInfo *fmt_info, i64 *v);
    Zstr _read_Zstr(Zstr i, FmtInfo *fmt_info, Zstr *v);
    Zstr _read_i16(Zstr i, FmtInfo *fmt_info, i16 *v);
    Zstr _read_i32(Zstr i, FmtInfo *fmt_info, i32 *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_i32(Zstr i, FmtInfo *fmt_info, i32 *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_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);
    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);
    #if FEATURE_FLOAT
    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);
    #if FEATURE_FLOAT
    Zstr _read_Float(Zstr i, FmtInfo *fmt_info, Float *value);
    Zstr _read_f64(Zstr i, FmtInfo *fmt_info, f64 *v);
    #if FEATURE_FLOAT
    Zstr _read_Float(Zstr i, FmtInfo *fmt_info, Float *value);
    #endif
    #if FEATURE_BITVEC
    #endif
    #if FEATURE_BITVEC
    Zstr _read_BitVec(Zstr i, FmtInfo *fmt_info, BitVec *bv);
    #endif
    #if FEATURE_INT
    #endif
    #if FEATURE_INT
    Zstr _read_Int(Zstr i, FmtInfo *fmt_info, Int *value);
    #endif
    /// TAGS: Buf, Read, Format, I/O
    ///
    bool buf_read_fmt(BufIter *iter, Zstr fmtstr, TypeSpecificIO *argv, u64 argc);
    
    ///
    /// TAGS: Buf, Append, Format, I/O
    ///
    bool buf_append_fmt(Buf *out, Zstr fmtstr, TypeSpecificIO *argv, u64 argc);
    
    ///
    /// TAGS: Buf, Write, Format, I/O
    ///
    bool buf_write_fmt(Buf *out, Zstr fmtstr, TypeSpecificIO *argv, u64 argc);
    
    ///
    /// TAGS: Buf, Patch, Format, I/O
    ///
    bool buf_patch_fmt(Buf *out, size offset, Zstr fmtstr, TypeSpecificIO *argv, u64 argc);
    
    ///
    
    #include <Misra/Std/Container/Vec/Type.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Utility/Iter.h>
    #include <Misra/Types.h>
    #include <Misra/Std/Memory.h>
    #include <Misra/Std/Utility/Iter.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
    /// TAGS: Buf, Read, Zstr, String
    ///
    static inline Zstr BufReadZstr(BufIter *c) {
        Zstr s = (Zstr)(c->data + c->pos);
        while (c->pos < c->length && c->data[c->pos] != 0) {
    ///
    static inline Zstr BufReadZstr(BufIter *c) {
        Zstr s = (Zstr)(c->data + c->pos);
        while (c->pos < c->length && c->data[c->pos] != 0) {
            c->pos++;
    /// TAGS: Buf, Write, Zstr, String
    ///
    static inline bool BufWriteZstr(Buf *b, Zstr s) {
        while (*s) {
            if (!VecPushBackR(b, (u8)*s)) {
        /// TAGS: Float, Convert, Parse, Decimal
        ///
        bool float_try_from_str_zstr(Float *out, Zstr text);
        bool float_try_from_str_str(Float *out, const Str *text);
    #define FloatTryFromStr(out, text)                                                                                     \
        bool float_try_from_str_str(Float *out, const Str *text);
    #define FloatTryFromStr(out, text)                                                                                     \
        _Generic((text), Str *: float_try_from_str_str, Zstr: float_try_from_str_zstr, char *: float_try_from_str_zstr)(   \
            (out),                                                                                                         \
            (text)                                                                                                         \
        /// TAGS: Float, Convert, String
        ///
        Float float_from_str_zstr(Zstr text, Allocator *alloc);
        Float float_from_str_str(const Str *text, Allocator *alloc);
    #define FloatFromStr(...) OVERLOAD(FloatFromStr, __VA_ARGS__)
    #define FloatFromStr(...) OVERLOAD(FloatFromStr, __VA_ARGS__)
    #define FloatFromStr_1(text)                                                                                           \
        _Generic((text), Str *: float_from_str_str, Zstr: float_from_str_zstr, char *: float_from_str_zstr)(               \
            (text),                                                                                                        \
            MisraScope                                                                                                     \
        )
    #define FloatFromStr_2(text, alloc)                                                                                    \
        _Generic((text), Str *: float_from_str_str, Zstr: float_from_str_zstr, char *: float_from_str_zstr)(               \
            (text),                                                                                                        \
            ALLOCATOR_OF(alloc)                                                                                            \
    #include "Type.h"
    #include <Misra/Std/Container/Str/Type.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
        /// TAGS: BitVec, Pattern, Regex, Match
        ///
        bool bitvec_regex_match_zstr(BitVec *bv, Zstr pattern);
        bool bitvec_regex_match_str(BitVec *bv, const Str *pattern);
    #define BitVecRegexMatch(bv, pattern)                                                                                   \
        bool bitvec_regex_match_str(BitVec *bv, const Str *pattern);
    #define BitVecRegexMatch(bv, pattern)                                                                                   \
        _Generic((pattern), Str *: bitvec_regex_match_str, Zstr: bitvec_regex_match_zstr, char *: bitvec_regex_match_zstr)( \
            (bv),                                                                                                           \
            (pattern)                                                                                                       \
        /// TAGS: BitVec, Convert, String, Allocator
        ///
        bool bitvec_try_from_str_zstr(BitVec *out, Zstr str, Allocator *alloc);
        bool bitvec_try_from_str_str(BitVec *out, const Str *str, Allocator *alloc);
    #define BitVecTryFromStr(...) OVERLOAD(BitVecTryFromStr, __VA_ARGS__)
    #define BitVecTryFromStr(...) OVERLOAD(BitVecTryFromStr, __VA_ARGS__)
    #define BitVecTryFromStr_2(out, str)                                                                                   \
        _Generic((str), Str *: bitvec_try_from_str_str, Zstr: bitvec_try_from_str_zstr, char *: bitvec_try_from_str_zstr)( \
            (out),                                                                                                         \
            (str),                                                                                                         \
        )
    #define BitVecTryFromStr_3(out, str, alloc)                                                                            \
        _Generic((str), Str *: bitvec_try_from_str_str, Zstr: bitvec_try_from_str_zstr, char *: bitvec_try_from_str_zstr)( \
            (out),                                                                                                         \
            (str),                                                                                                         \
        /// TAGS: BitVec, Convert, String, Allocator
        ///
        BitVec bitvec_from_str_zstr(Zstr str, Allocator *alloc);
        BitVec bitvec_from_str_str(const Str *str, Allocator *alloc);
    #define BitVecFromStr(...) OVERLOAD(BitVecFromStr, __VA_ARGS__)
    #define BitVecFromStr(...) OVERLOAD(BitVecFromStr, __VA_ARGS__)
    #define BitVecFromStr_1(str)                                                                                           \
        _Generic((str), Str *: bitvec_from_str_str, Zstr: bitvec_from_str_zstr, char *: bitvec_from_str_zstr)(             \
            (str),                                                                                                         \
            MisraScope                                                                                                     \
        )
    #define BitVecFromStr_2(str, alloc)                                                                                    \
        _Generic((str), Str *: bitvec_from_str_str, Zstr: bitvec_from_str_zstr, char *: bitvec_from_str_zstr)(             \
            (str),                                                                                                         \
            ALLOCATOR_OF(alloc)                                                                                            \
        /// TAGS: Int, Convert, Parse, Radix
        ///
        bool int_try_from_str_radix_zstr(Int *out, Zstr digits, u8 radix);
        bool int_try_from_str_radix_str(Int *out, const Str *digits, u8 radix);
    #define IntTryFromStrRadix(out, digits, radix)                                                                                     \
        bool int_try_from_str_radix_str(Int *out, const Str *digits, u8 radix);
    #define IntTryFromStrRadix(out, digits, radix)                                                                                     \
        _Generic((digits), Str *: int_try_from_str_radix_str, Zstr: int_try_from_str_radix_zstr, char *: int_try_from_str_radix_zstr)( \
            (out),                                                                                                                     \
            (digits),                                                                                                                  \
        /// TAGS: Int, Convert, Radix, String
        ///
        Int int_from_str_radix_zstr(Zstr digits, u8 radix, Allocator *alloc);
        Int int_from_str_radix_str(const Str *digits, u8 radix, Allocator *alloc);
    #define IntFromStrRadix(...) OVERLOAD(IntFromStrRadix, __VA_ARGS__)
    #define IntFromStrRadix(...) OVERLOAD(IntFromStrRadix, __VA_ARGS__)
    #define IntFromStrRadix_2(digits, radix)                                                                               \
        _Generic((digits), Str *: int_from_str_radix_str, Zstr: int_from_str_radix_zstr, char *: int_from_str_radix_zstr)( \
            (digits),                                                                                                      \
            (radix),                                                                                                       \
        )
    #define IntFromStrRadix_3(digits, radix, alloc)                                                                        \
        _Generic((digits), Str *: int_from_str_radix_str, Zstr: int_from_str_radix_zstr, char *: int_from_str_radix_zstr)( \
            (digits),                                                                                                      \
            (radix),                                                                                                       \
        /// TAGS: Int, Convert, Parse, Decimal
        ///
        bool int_try_from_str_zstr(Int *out, Zstr decimal);
        bool int_try_from_str_str(Int *out, const Str *decimal);
    #define IntTryFromStr(out, decimal)                                                                                    \
        bool int_try_from_str_str(Int *out, const Str *decimal);
    #define IntTryFromStr(out, decimal)                                                                                    \
        _Generic((decimal), Str *: int_try_from_str_str, Zstr: int_try_from_str_zstr, char *: int_try_from_str_zstr)(      \
            (out),                                                                                                         \
            (decimal)                                                                                                      \
        /// TAGS: Int, Convert, String
        ///
        Int int_from_str_zstr(Zstr decimal, Allocator *alloc);
        Int int_from_str_str(const Str *decimal, Allocator *alloc);
    #define IntFromStr(...) OVERLOAD(IntFromStr, __VA_ARGS__)
    #define IntFromStr(...) OVERLOAD(IntFromStr, __VA_ARGS__)
    #define IntFromStr_1(decimal)                                                                                          \
        _Generic((decimal), Str *: int_from_str_str, Zstr: int_from_str_zstr, char *: int_from_str_zstr)(                  \
            (decimal),                                                                                                     \
            MisraScope                                                                                                     \
        )
    #define IntFromStr_2(decimal, alloc)                                                                                   \
        _Generic((decimal), Str *: int_from_str_str, Zstr: int_from_str_zstr, char *: int_from_str_zstr)(                  \
            (decimal),                                                                                                     \
            ALLOCATOR_OF(alloc)                                                                                            \
        /// TAGS: Int, Convert, Parse, Binary
        ///
        bool int_try_from_binary_zstr(Int *out, Zstr binary);
        bool int_try_from_binary_str(Int *out, const Str *binary);
    #define IntTryFromBinary(out, binary)                                                                                     \
        bool int_try_from_binary_str(Int *out, const Str *binary);
    #define IntTryFromBinary(out, binary)                                                                                     \
        _Generic((binary), Str *: int_try_from_binary_str, Zstr: int_try_from_binary_zstr, char *: int_try_from_binary_zstr)( \
            (out),                                                                                                            \
            (binary)                                                                                                          \
        /// TAGS: Int, Convert, Binary
        ///
        Int int_from_binary_zstr(Zstr binary, Allocator *alloc);
        Int int_from_binary_str(const Str *binary, Allocator *alloc);
    #define IntFromBinary(...) OVERLOAD(IntFromBinary, __VA_ARGS__)
    #define IntFromBinary(...) OVERLOAD(IntFromBinary, __VA_ARGS__)
    #define IntFromBinary_1(binary)                                                                                        \
        _Generic((binary), Str *: int_from_binary_str, Zstr: int_from_binary_zstr, char *: int_from_binary_zstr)(          \
            (binary),                                                                                                      \
            MisraScope                                                                                                     \
        )
    #define IntFromBinary_2(binary, alloc)                                                                                 \
        _Generic((binary), Str *: int_from_binary_str, Zstr: int_from_binary_zstr, char *: int_from_binary_zstr)(          \
            (binary),                                                                                                      \
            ALLOCATOR_OF(alloc)                                                                                            \
        /// TAGS: Int, Convert, Parse, Octal
        ///
        bool int_try_from_oct_str_zstr(Int *out, Zstr octal);
        bool int_try_from_oct_str_str(Int *out, const Str *octal);
    #define IntTryFromOctStr(out, octal)                                                                                        \
        bool int_try_from_oct_str_str(Int *out, const Str *octal);
    #define IntTryFromOctStr(out, octal)                                                                                        \
        _Generic((octal), Str *: int_try_from_oct_str_str, Zstr: int_try_from_oct_str_zstr, char *: int_try_from_oct_str_zstr)( \
            (out),                                                                                                              \
            (octal)                                                                                                             \
        /// TAGS: Int, Convert, Oct
        ///
        Int int_from_oct_str_zstr(Zstr octal, Allocator *alloc);
        Int int_from_oct_str_str(const Str *octal, Allocator *alloc);
    #define IntFromOctStr(...) OVERLOAD(IntFromOctStr, __VA_ARGS__)
    #define IntFromOctStr(...) OVERLOAD(IntFromOctStr, __VA_ARGS__)
    #define IntFromOctStr_1(octal)                                                                                         \
        _Generic((octal), Str *: int_from_oct_str_str, Zstr: int_from_oct_str_zstr, char *: int_from_oct_str_zstr)(        \
            (octal),                                                                                                       \
            MisraScope                                                                                                     \
        )
    #define IntFromOctStr_2(octal, alloc)                                                                                  \
        _Generic((octal), Str *: int_from_oct_str_str, Zstr: int_from_oct_str_zstr, char *: int_from_oct_str_zstr)(        \
            (octal),                                                                                                       \
            ALLOCATOR_OF(alloc)                                                                                            \
        /// TAGS: Int, Convert, Parse, Hex
        ///
        bool int_try_from_hex_str_zstr(Int *out, Zstr hex);
        bool int_try_from_hex_str_str(Int *out, const Str *hex);
    #define IntTryFromHexStr(out, hex)                                                                                        \
        bool int_try_from_hex_str_str(Int *out, const Str *hex);
    #define IntTryFromHexStr(out, hex)                                                                                        \
        _Generic((hex), Str *: int_try_from_hex_str_str, Zstr: int_try_from_hex_str_zstr, char *: int_try_from_hex_str_zstr)( \
            (out),                                                                                                            \
            (hex)                                                                                                             \
        /// TAGS: Int, Convert, Hex
        ///
        Int int_from_hex_str_zstr(Zstr hex, Allocator *alloc);
        Int int_from_hex_str_str(const Str *hex, Allocator *alloc);
    #define IntFromHexStr(...) OVERLOAD(IntFromHexStr, __VA_ARGS__)
    #define IntFromHexStr(...) OVERLOAD(IntFromHexStr, __VA_ARGS__)
    #define IntFromHexStr_1(hex)                                                                                           \
        _Generic((hex), Str *: int_from_hex_str_str, Zstr: int_from_hex_str_zstr, char *: int_from_hex_str_zstr)(          \
            (hex),                                                                                                         \
            MisraScope                                                                                                     \
        )
    #define IntFromHexStr_2(hex, alloc)                                                                                    \
        _Generic((hex), Str *: int_from_hex_str_str, Zstr: int_from_hex_str_zstr, char *: int_from_hex_str_zstr)(          \
            (hex),                                                                                                         \
            ALLOCATOR_OF(alloc)                                                                                            \
    #include "Type.h"
    #include <Misra/Std/Memory.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Vec/Type.h>
        /// TAGS: Str, Init, Cstr
        ///
        bool str_try_init_from_cstr(Str *out, Zstr cstr, size len, Allocator *alloc);
    
        ///
        /// TAGS: Str, Init, Cstr
        ///
        Str  str_init_from_cstr(Zstr cstr, size len, Allocator *alloc);
    
    ///
    #include "Type.h"
    #include <Misra/Std/Container/Vec/Insert.h>
    #include <Misra/Std/Zstr.h>
    
    #ifdef __cplusplus
    #define StrInsertMany(...) OVERLOAD(StrInsertMany, __VA_ARGS__)
    #define StrInsertMany_3(str, zstr, idx)                                                                            \
        _Generic((zstr), Zstr: VecInsertRangeR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))), char *: VecInsertRangeR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))))
    #define StrInsertMany_4(str, cstr, cstr_len, idx)                                                                  \
        _Generic((cstr), Zstr: VecInsertRangeR((str), (Zstr)(cstr), (idx), (cstr_len)), char *: VecInsertRangeR((str), (Zstr)(cstr), (idx), (cstr_len)))
        _Generic((zstr), Zstr: VecInsertRangeR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))), char *: VecInsertRangeR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))))
    #define StrInsertMany_4(str, cstr, cstr_len, idx)                                                                  \
        _Generic((cstr), Zstr: VecInsertRangeR((str), (Zstr)(cstr), (idx), (cstr_len)), char *: VecInsertRangeR((str), (Zstr)(cstr), (idx), (cstr_len)))
    
    ///
    #define StrMustInsertMany(...) OVERLOAD(StrMustInsertMany, __VA_ARGS__)
    #define StrMustInsertMany_3(str, zstr, idx)                                                                        \
        _Generic((zstr), Zstr: VecMustInsertRangeR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))), char *: VecMustInsertRangeR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))))
    #define StrMustInsertMany_4(str, cstr, cstr_len, idx)                                                              \
        _Generic((cstr), Zstr: VecMustInsertRangeR((str), (Zstr)(cstr), (idx), (cstr_len)), char *: VecMustInsertRangeR((str), (Zstr)(cstr), (idx), (cstr_len)))
        _Generic((zstr), Zstr: VecMustInsertRangeR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))), char *: VecMustInsertRangeR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))))
    #define StrMustInsertMany_4(str, cstr, cstr_len, idx)                                                              \
        _Generic((cstr), Zstr: VecMustInsertRangeR((str), (Zstr)(cstr), (idx), (cstr_len)), char *: VecMustInsertRangeR((str), (Zstr)(cstr), (idx), (cstr_len)))
    
    ///
    #define StrInsertManyFast(...) OVERLOAD(StrInsertManyFast, __VA_ARGS__)
    #define StrInsertManyFast_3(str, zstr, idx)                                                                        \
        _Generic((zstr), Zstr: VecInsertRangeFastR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))), char *: VecInsertRangeFastR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))))
    #define StrInsertManyFast_4(str, cstr, cstr_len, idx)                                                              \
        _Generic((cstr), Zstr: VecInsertRangeFastR((str), (Zstr)(cstr), (idx), (cstr_len)), char *: VecInsertRangeFastR((str), (Zstr)(cstr), (idx), (cstr_len)))
        _Generic((zstr), Zstr: VecInsertRangeFastR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))), char *: VecInsertRangeFastR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))))
    #define StrInsertManyFast_4(str, cstr, cstr_len, idx)                                                              \
        _Generic((cstr), Zstr: VecInsertRangeFastR((str), (Zstr)(cstr), (idx), (cstr_len)), char *: VecInsertRangeFastR((str), (Zstr)(cstr), (idx), (cstr_len)))
    
    ///
    #define StrMustInsertManyFast(...) OVERLOAD(StrMustInsertManyFast, __VA_ARGS__)
    #define StrMustInsertManyFast_3(str, zstr, idx)                                                                    \
        _Generic((zstr), Zstr: VecMustInsertRangeFastR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))), char *: VecMustInsertRangeFastR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))))
    #define StrMustInsertManyFast_4(str, cstr, cstr_len, idx)                                                          \
        _Generic((cstr), Zstr: VecMustInsertRangeFastR((str), (Zstr)(cstr), (idx), (cstr_len)), char *: VecMustInsertRangeFastR((str), (Zstr)(cstr), (idx), (cstr_len)))
        _Generic((zstr), Zstr: VecMustInsertRangeFastR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))), char *: VecMustInsertRangeFastR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))))
    #define StrMustInsertManyFast_4(str, cstr, cstr_len, idx)                                                          \
        _Generic((cstr), Zstr: VecMustInsertRangeFastR((str), (Zstr)(cstr), (idx), (cstr_len)), char *: VecMustInsertRangeFastR((str), (Zstr)(cstr), (idx), (cstr_len)))
    
    // ---------------------------------------------------------------------------
    #define StrPushBackMany(...) OVERLOAD(StrPushBackMany, __VA_ARGS__)
    #define StrPushBackMany_2(str, zstr)                                                                               \
        _Generic((zstr), Zstr: VecPushBackArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecPushBackArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    #define StrPushBackMany_3(str, cstr, cstr_len)                                                                     \
        _Generic((cstr), Zstr: VecPushBackArrR((str), (Zstr)(cstr), (cstr_len)), char *: VecPushBackArrR((str), (Zstr)(cstr), (cstr_len)))
        _Generic((zstr), Zstr: VecPushBackArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecPushBackArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    #define StrPushBackMany_3(str, cstr, cstr_len)                                                                     \
        _Generic((cstr), Zstr: VecPushBackArrR((str), (Zstr)(cstr), (cstr_len)), char *: VecPushBackArrR((str), (Zstr)(cstr), (cstr_len)))
    
    ///
    #define StrMustPushBackMany(...) OVERLOAD(StrMustPushBackMany, __VA_ARGS__)
    #define StrMustPushBackMany_2(str, zstr)                                                                           \
        _Generic((zstr), Zstr: VecMustPushBackArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecMustPushBackArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    #define StrMustPushBackMany_3(str, cstr, cstr_len)                                                                 \
        _Generic((cstr), Zstr: VecMustPushBackArrR((str), (Zstr)(cstr), (cstr_len)), char *: VecMustPushBackArrR((str), (Zstr)(cstr), (cstr_len)))
        _Generic((zstr), Zstr: VecMustPushBackArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecMustPushBackArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    #define StrMustPushBackMany_3(str, cstr, cstr_len)                                                                 \
        _Generic((cstr), Zstr: VecMustPushBackArrR((str), (Zstr)(cstr), (cstr_len)), char *: VecMustPushBackArrR((str), (Zstr)(cstr), (cstr_len)))
    
    // ---------------------------------------------------------------------------
    #define StrPushFrontMany(...) OVERLOAD(StrPushFrontMany, __VA_ARGS__)
    #define StrPushFrontMany_2(str, zstr)                                                                              \
        _Generic((zstr), Zstr: VecPushFrontArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecPushFrontArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    #define StrPushFrontMany_3(str, cstr, cstr_len)                                                                    \
        _Generic((cstr), Zstr: VecPushFrontArrR((str), (Zstr)(cstr), (cstr_len)), char *: VecPushFrontArrR((str), (Zstr)(cstr), (cstr_len)))
        _Generic((zstr), Zstr: VecPushFrontArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecPushFrontArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    #define StrPushFrontMany_3(str, cstr, cstr_len)                                                                    \
        _Generic((cstr), Zstr: VecPushFrontArrR((str), (Zstr)(cstr), (cstr_len)), char *: VecPushFrontArrR((str), (Zstr)(cstr), (cstr_len)))
    
    ///
    #define StrMustPushFrontMany(...) OVERLOAD(StrMustPushFrontMany, __VA_ARGS__)
    #define StrMustPushFrontMany_2(str, zstr)                                                                          \
        _Generic((zstr), Zstr: VecMustPushFrontArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecMustPushFrontArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    #define StrMustPushFrontMany_3(str, cstr, cstr_len)                                                                \
        _Generic((cstr), Zstr: VecMustPushFrontArrR((str), (Zstr)(cstr), (cstr_len)), char *: VecMustPushFrontArrR((str), (Zstr)(cstr), (cstr_len)))
        _Generic((zstr), Zstr: VecMustPushFrontArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecMustPushFrontArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    #define StrMustPushFrontMany_3(str, cstr, cstr_len)                                                                \
        _Generic((cstr), Zstr: VecMustPushFrontArrR((str), (Zstr)(cstr), (cstr_len)), char *: VecMustPushFrontArrR((str), (Zstr)(cstr), (cstr_len)))
    
    ///
    #define StrPushFrontManyFast(...) OVERLOAD(StrPushFrontManyFast, __VA_ARGS__)
    #define StrPushFrontManyFast_2(str, zstr)                                                                          \
        _Generic((zstr), Zstr: VecPushFrontArrFastR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecPushFrontArrFastR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    #define StrPushFrontManyFast_3(str, cstr, cstr_len)                                                                \
        _Generic((cstr), Zstr: VecPushFrontArrFastR((str), (Zstr)(cstr), (cstr_len)), char *: VecPushFrontArrFastR((str), (Zstr)(cstr), (cstr_len)))
        _Generic((zstr), Zstr: VecPushFrontArrFastR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecPushFrontArrFastR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    #define StrPushFrontManyFast_3(str, cstr, cstr_len)                                                                \
        _Generic((cstr), Zstr: VecPushFrontArrFastR((str), (Zstr)(cstr), (cstr_len)), char *: VecPushFrontArrFastR((str), (Zstr)(cstr), (cstr_len)))
    
    ///
    #define StrMustPushFrontManyFast(...) OVERLOAD(StrMustPushFrontManyFast, __VA_ARGS__)
    #define StrMustPushFrontManyFast_2(str, zstr)                                                                      \
        _Generic((zstr), Zstr: VecMustPushFrontArrFastR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecMustPushFrontArrFastR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    #define StrMustPushFrontManyFast_3(str, cstr, cstr_len)                                                            \
        _Generic((cstr), Zstr: VecMustPushFrontArrFastR((str), (Zstr)(cstr), (cstr_len)), char *: VecMustPushFrontArrFastR((str), (Zstr)(cstr), (cstr_len)))
        _Generic((zstr), Zstr: VecMustPushFrontArrFastR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecMustPushFrontArrFastR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    #define StrMustPushFrontManyFast_3(str, cstr, cstr_len)                                                            \
        _Generic((cstr), Zstr: VecMustPushFrontArrFastR((str), (Zstr)(cstr), (cstr_len)), char *: VecMustPushFrontArrFastR((str), (Zstr)(cstr), (cstr_len)))
    
    ///
    #include "Type.h"
    #include <Misra/Std/Utility/StrIter.h>
    #include <Misra/Std/Zstr.h>
    
    #ifdef __cplusplus
            (other),                                                                                                       \
            Str *: str_cmp_str ((s), (const Str *)(other)),                                                                \
            Zstr:  str_cmp_zstr((s), (Zstr)(other)),                                                                        \
            char *: str_cmp_zstr((s), (Zstr)(other))                                                                        \
        )
            Str *: str_cmp_str ((s), (const Str *)(other)),                                                                \
            Zstr:  str_cmp_zstr((s), (Zstr)(other)),                                                                        \
            char *: str_cmp_zstr((s), (Zstr)(other))                                                                        \
        )
    #define StrCmp_3(s, other, other_len) str_cmp_cstr((s), (Zstr)(other), (other_len))
            char *: str_cmp_zstr((s), (Zstr)(other))                                                                        \
        )
    #define StrCmp_3(s, other, other_len) str_cmp_cstr((s), (Zstr)(other), (other_len))
    
    ///
            (other),                                                                                                       \
            Str *: str_cmp_str_ignore_case ((s), (const Str *)(other)),                                                    \
            Zstr:  str_cmp_zstr_ignore_case((s), (Zstr)(other)),                                                            \
            char *: str_cmp_zstr_ignore_case((s), (Zstr)(other))                                                            \
        )
            Str *: str_cmp_str_ignore_case ((s), (const Str *)(other)),                                                    \
            Zstr:  str_cmp_zstr_ignore_case((s), (Zstr)(other)),                                                            \
            char *: str_cmp_zstr_ignore_case((s), (Zstr)(other))                                                            \
        )
    #define StrCmpIgnoreCase_3(s, other, other_len) str_cmp_cstr_ignore_case((s), (Zstr)(other), (other_len))
            char *: str_cmp_zstr_ignore_case((s), (Zstr)(other))                                                            \
        )
    #define StrCmpIgnoreCase_3(s, other, other_len) str_cmp_cstr_ignore_case((s), (Zstr)(other), (other_len))
    
    //
            (key),                                                                                                         \
            Str *: str_find_str ((s), (const Str *)(key)),                                                                 \
            Zstr:  str_find_zstr((s), (Zstr)(key)),                                                                         \
            char *: str_find_zstr((s), (Zstr)(key))                                                                         \
        )
            Str *: str_find_str ((s), (const Str *)(key)),                                                                 \
            Zstr:  str_find_zstr((s), (Zstr)(key)),                                                                         \
            char *: str_find_zstr((s), (Zstr)(key))                                                                         \
        )
    #define StrFind_3(s, key, key_len) str_find_cstr((s), (Zstr)(key), (key_len))
            char *: str_find_zstr((s), (Zstr)(key))                                                                         \
        )
    #define StrFind_3(s, key, key_len) str_find_cstr((s), (Zstr)(key), (key_len))
    
    ///
            (key),                                                                                                         \
            Str *: str_index_of_str ((s), (const Str *)(key)),                                                             \
            Zstr:  str_index_of_zstr((s), (Zstr)(key)),                                                                     \
            char *: str_index_of_zstr((s), (Zstr)(key))                                                                     \
        )
            Str *: str_index_of_str ((s), (const Str *)(key)),                                                             \
            Zstr:  str_index_of_zstr((s), (Zstr)(key)),                                                                     \
            char *: str_index_of_zstr((s), (Zstr)(key))                                                                     \
        )
    #define StrIndexOf_3(s, key, key_len) str_index_of_cstr((s), (Zstr)(key), (key_len))
            char *: str_index_of_zstr((s), (Zstr)(key))                                                                     \
        )
    #define StrIndexOf_3(s, key, key_len) str_index_of_cstr((s), (Zstr)(key), (key_len))
    
    ///
            (key),                                                                                                         \
            Str *: str_contains_str ((s), (const Str *)(key)),                                                             \
            Zstr:  str_contains_zstr((s), (Zstr)(key)),                                                                     \
            char *: str_contains_zstr((s), (Zstr)(key))                                                                     \
        )
            Str *: str_contains_str ((s), (const Str *)(key)),                                                             \
            Zstr:  str_contains_zstr((s), (Zstr)(key)),                                                                     \
            char *: str_contains_zstr((s), (Zstr)(key))                                                                     \
        )
    #define StrContains_3(s, key, key_len) str_contains_cstr((s), (Zstr)(key), (key_len))
            char *: str_contains_zstr((s), (Zstr)(key))                                                                     \
        )
    #define StrContains_3(s, key, key_len) str_contains_cstr((s), (Zstr)(key), (key_len))
    
    //
            (prefix),                                                                                                      \
            Str *: str_starts_with_str ((s), (const Str *)(prefix)),                                                       \
            Zstr:  str_starts_with_zstr((s), (Zstr)(prefix)),                                                               \
            char *: str_starts_with_zstr((s), (Zstr)(prefix))                                                               \
        )
            Str *: str_starts_with_str ((s), (const Str *)(prefix)),                                                       \
            Zstr:  str_starts_with_zstr((s), (Zstr)(prefix)),                                                               \
            char *: str_starts_with_zstr((s), (Zstr)(prefix))                                                               \
        )
    #define StrStartsWith_3(s, prefix, prefix_len) str_starts_with_cstr((s), (Zstr)(prefix), (prefix_len))
            char *: str_starts_with_zstr((s), (Zstr)(prefix))                                                               \
        )
    #define StrStartsWith_3(s, prefix, prefix_len) str_starts_with_cstr((s), (Zstr)(prefix), (prefix_len))
    
    ///
            (suffix),                                                                                                      \
            Str *: str_ends_with_str ((s), (const Str *)(suffix)),                                                         \
            Zstr:  str_ends_with_zstr((s), (Zstr)(suffix)),                                                                 \
            char *: str_ends_with_zstr((s), (Zstr)(suffix))                                                                 \
        )
            Str *: str_ends_with_str ((s), (const Str *)(suffix)),                                                         \
            Zstr:  str_ends_with_zstr((s), (Zstr)(suffix)),                                                                 \
            char *: str_ends_with_zstr((s), (Zstr)(suffix))                                                                 \
        )
    #define StrEndsWith_3(s, suffix, suffix_len) str_ends_with_cstr((s), (Zstr)(suffix), (suffix_len))
            char *: str_ends_with_zstr((s), (Zstr)(suffix))                                                                 \
        )
    #define StrEndsWith_3(s, suffix, suffix_len) str_ends_with_cstr((s), (Zstr)(suffix), (suffix_len))
    
    //
            (match),                                                                                                       \
            Str *: str_replace_str ((s), (const Str *)(match), (const Str *)(replacement), (count)),                       \
            Zstr:  str_replace_zstr((s), (Zstr)(match), (Zstr)(replacement), (count)),                                      \
            char *: str_replace_zstr((s), (Zstr)(match), (Zstr)(replacement), (count))                                      \
        )
            Str *: str_replace_str ((s), (const Str *)(match), (const Str *)(replacement), (count)),                       \
            Zstr:  str_replace_zstr((s), (Zstr)(match), (Zstr)(replacement), (count)),                                      \
            char *: str_replace_zstr((s), (Zstr)(match), (Zstr)(replacement), (count))                                      \
        )
    #define StrReplace_6(s, match, match_len, replacement, replacement_len, count)                                         \
        )
    #define StrReplace_6(s, match, match_len, replacement, replacement_len, count)                                         \
        str_replace_cstr((s), (Zstr)(match), (match_len), (Zstr)(replacement), (replacement_len), (count))
    
    //
            (key),                                                                                                         \
            Str *: str_split_to_iters_str ((s), (const Str *)(key)),                                                       \
            Zstr:  str_split_to_iters_zstr((s), (Zstr)(key)),                                                               \
            char *: str_split_to_iters_zstr((s), (Zstr)(key))                                                               \
        )
            Str *: str_split_to_iters_str ((s), (const Str *)(key)),                                                       \
            Zstr:  str_split_to_iters_zstr((s), (Zstr)(key)),                                                               \
            char *: str_split_to_iters_zstr((s), (Zstr)(key))                                                               \
        )
            (key),                                                                                                         \
            Str *: str_split_str ((s), (const Str *)(key)),                                                                \
            Zstr:  str_split_zstr((s), (Zstr)(key)),                                                                        \
            char *: str_split_zstr((s), (Zstr)(key))                                                                        \
        )
            Str *: str_split_str ((s), (const Str *)(key)),                                                                \
            Zstr:  str_split_zstr((s), (Zstr)(key)),                                                                        \
            char *: str_split_zstr((s), (Zstr)(key))                                                                        \
        )
    
    #include <Misra/Std/Container/Common.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
    ///
    typedef struct {
        Zstr                    name;
        MapPolicyShouldRehashFn should_rehash;
        MapPolicyNextCapacityFn next_capacity;
    /// TAGS: Socket, Address
    ///
    bool socket_addr_parse_zstr(SocketAddr *out, Zstr spec, SocketKind kind);
    
    ///
            (spec),                                                                                                                                               \
            Str *: socket_addr_parse_str((out), (const Str *)(spec), (kind)),                                                                                     \
            Zstr: socket_addr_parse_zstr((out), (Zstr)(spec), (kind)),                                                                                            \
            char *: socket_addr_parse_zstr((out), (Zstr)(spec), (kind))                                                                                           \
        )
            Str *: socket_addr_parse_str((out), (const Str *)(spec), (kind)),                                                                                     \
            Zstr: socket_addr_parse_zstr((out), (Zstr)(spec), (kind)),                                                                                            \
            char *: socket_addr_parse_zstr((out), (Zstr)(spec), (kind))                                                                                           \
        )
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Zstr.h>
    
    typedef enum DirEntryType {
    /// TAGS: System, Conversion, String, Utility
    ///
    Zstr DirEntryTypeToZstr(DirEntryType type);
    
    ///
    /// TAGS: System, FileSystem, Directory
    ///
    DirContents dir_get_contents(Zstr path, Allocator *alloc);
    #define DirGetContents(...) OVERLOAD(DirGetContents, __VA_ARGS__)
    #define DirGetContents_1(path)                                                                                         \
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: dir_get_contents((Zstr)StrBegin((Str *)(path)), MisraScope),                                            \
            Zstr: dir_get_contents((Zstr)(path), MisraScope),                                                              \
            char *: dir_get_contents((Zstr)(path), MisraScope)                                                             \
            (path),                                                                                                        \
            Str *: dir_get_contents((Zstr)StrBegin((Str *)(path)), MisraScope),                                            \
            Zstr: dir_get_contents((Zstr)(path), MisraScope),                                                              \
            char *: dir_get_contents((Zstr)(path), MisraScope)                                                             \
        )
            Str *: dir_get_contents((Zstr)StrBegin((Str *)(path)), MisraScope),                                            \
            Zstr: dir_get_contents((Zstr)(path), MisraScope),                                                              \
            char *: dir_get_contents((Zstr)(path), MisraScope)                                                             \
        )
    #define DirGetContents_2(path, alloc)                                                                                  \
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: dir_get_contents((Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                   \
            Zstr: dir_get_contents((Zstr)(path), ALLOCATOR_OF(alloc)),                                                     \
            char *: dir_get_contents((Zstr)(path), ALLOCATOR_OF(alloc))                                                    \
            (path),                                                                                                        \
            Str *: dir_get_contents((Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                   \
            Zstr: dir_get_contents((Zstr)(path), ALLOCATOR_OF(alloc)),                                                     \
            char *: dir_get_contents((Zstr)(path), ALLOCATOR_OF(alloc))                                                    \
        )
            Str *: dir_get_contents((Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                   \
            Zstr: dir_get_contents((Zstr)(path), ALLOCATOR_OF(alloc)),                                                     \
            char *: dir_get_contents((Zstr)(path), ALLOCATOR_OF(alloc))                                                    \
        )
    /// TAGS: System, File, Metadata
    ///
    i64 file_get_size(Zstr filename);
    #define FileGetSize(path)                                                                                              \
        _Generic(                                                                                                          \
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: file_get_size((Zstr)StrBegin((Str *)(path))),                                                           \
            Zstr: file_get_size((Zstr)(path)),                                                                             \
            char *: file_get_size((Zstr)(path))                                                                            \
            (path),                                                                                                        \
            Str *: file_get_size((Zstr)StrBegin((Str *)(path))),                                                           \
            Zstr: file_get_size((Zstr)(path)),                                                                             \
            char *: file_get_size((Zstr)(path))                                                                            \
        )
            Str *: file_get_size((Zstr)StrBegin((Str *)(path))),                                                           \
            Zstr: file_get_size((Zstr)(path)),                                                                             \
            char *: file_get_size((Zstr)(path))                                                                            \
        )
    /// TAGS: System, File, FileSystem
    ///
    i8 file_remove(Zstr path);
    #define FileRemove(path)                                                                                               \
        _Generic(                                                                                                          \
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: file_remove((Zstr)StrBegin((Str *)(path))),                                                             \
            Zstr: file_remove((Zstr)(path)),                                                                               \
            char *: file_remove((Zstr)(path))                                                                              \
            (path),                                                                                                        \
            Str *: file_remove((Zstr)StrBegin((Str *)(path))),                                                             \
            Zstr: file_remove((Zstr)(path)),                                                                               \
            char *: file_remove((Zstr)(path))                                                                              \
        )
            Str *: file_remove((Zstr)StrBegin((Str *)(path))),                                                             \
            Zstr: file_remove((Zstr)(path)),                                                                               \
            char *: file_remove((Zstr)(path))                                                                              \
        )
    /// TAGS: System, Directory, FileSystem
    ///
    i8 dir_remove(Zstr path);
    #define DirRemove(path)                                                                                                \
        _Generic(                                                                                                          \
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: dir_remove((Zstr)StrBegin((Str *)(path))),                                                              \
            Zstr: dir_remove((Zstr)(path)),                                                                                \
            char *: dir_remove((Zstr)(path))                                                                               \
            (path),                                                                                                        \
            Str *: dir_remove((Zstr)StrBegin((Str *)(path))),                                                              \
            Zstr: dir_remove((Zstr)(path)),                                                                                \
            char *: dir_remove((Zstr)(path))                                                                               \
        )
            Str *: dir_remove((Zstr)StrBegin((Str *)(path))),                                                              \
            Zstr: dir_remove((Zstr)(path)),                                                                                \
            char *: dir_remove((Zstr)(path))                                                                               \
        )
    /// TAGS: System, Directory, FileSystem
    ///
    i8 dir_create(Zstr path);
    #define DirCreate(path)                                                                                                \
        _Generic(                                                                                                          \
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: dir_create((Zstr)StrBegin((Str *)(path))),                                                              \
            Zstr: dir_create((Zstr)(path)),                                                                                \
            char *: dir_create((Zstr)(path))                                                                               \
            (path),                                                                                                        \
            Str *: dir_create((Zstr)StrBegin((Str *)(path))),                                                              \
            Zstr: dir_create((Zstr)(path)),                                                                                \
            char *: dir_create((Zstr)(path))                                                                               \
        )
            Str *: dir_create((Zstr)StrBegin((Str *)(path))),                                                              \
            Zstr: dir_create((Zstr)(path)),                                                                                \
            char *: dir_create((Zstr)(path))                                                                               \
        )
    /// TAGS: System, Directory, FileSystem
    ///
    i8 dir_create_all(Zstr path);
    #define DirCreateAll(path)                                                                                             \
        _Generic(                                                                                                          \
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: dir_create_all((Zstr)StrBegin((Str *)(path))),                                                          \
            Zstr: dir_create_all((Zstr)(path)),                                                                            \
            char *: dir_create_all((Zstr)(path))                                                                           \
            (path),                                                                                                        \
            Str *: dir_create_all((Zstr)StrBegin((Str *)(path))),                                                          \
            Zstr: dir_create_all((Zstr)(path)),                                                                            \
            char *: dir_create_all((Zstr)(path))                                                                           \
        )
            Str *: dir_create_all((Zstr)StrBegin((Str *)(path))),                                                          \
            Zstr: dir_create_all((Zstr)(path)),                                                                            \
            char *: dir_create_all((Zstr)(path))                                                                           \
        )
    /// TAGS: System, Directory, FileSystem
    ///
    i8 dir_remove_all(Zstr path);
    #define DirRemoveAll(path)                                                                                             \
        _Generic(                                                                                                          \
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: dir_remove_all((Zstr)StrBegin((Str *)(path))),                                                          \
            Zstr: dir_remove_all((Zstr)(path)),                                                                            \
            char *: dir_remove_all((Zstr)(path))                                                                           \
            (path),                                                                                                        \
            Str *: dir_remove_all((Zstr)StrBegin((Str *)(path))),                                                          \
            Zstr: dir_remove_all((Zstr)(path)),                                                                            \
            char *: dir_remove_all((Zstr)(path))                                                                           \
        )
            Str *: dir_remove_all((Zstr)StrBegin((Str *)(path))),                                                          \
            Zstr: dir_remove_all((Zstr)(path)),                                                                            \
            char *: dir_remove_all((Zstr)(path))                                                                           \
        )
    bool pdb_cache_resolve_zstr(
        PdbCache *self,
        Zstr      module_path,
        u64       module_base,
        u64       runtime_ip,
        u64       module_base,
        u64       runtime_ip,
        Zstr     *out_name,
        u32      *out_offset
    );
        u64        module_base,
        u64        runtime_ip,
        Zstr      *out_name,
        u32       *out_offset
    );
                     (out_offset)                                                                                          \
                 ),                                                                                                        \
            Zstr: pdb_cache_resolve_zstr(                                                                                  \
                (self),                                                                                                    \
                (Zstr)(module_path),                                                                                       \
            Zstr: pdb_cache_resolve_zstr(                                                                                  \
                (self),                                                                                                    \
                (Zstr)(module_path),                                                                                       \
                (module_base),                                                                                             \
                (runtime_ip),                                                                                              \
            char *: pdb_cache_resolve_zstr(                                                                                \
                (self),                                                                                                    \
                (Zstr)(module_path),                                                                                       \
                (module_base),                                                                                             \
                (runtime_ip),                                                                                              \
        /// TAGS: Sys, Proc, Spawn
        ///
        Proc proc_init(Zstr path, char **argv, char **envp, Allocator *alloc);
    
    #define ProcInit(...)                       OVERLOAD(ProcInit, __VA_ARGS__)
            Str UNPL(buf) = StrInit();                                                                                     \
            ProcReadFromStdout((p), &UNPL(buf));                                                                           \
            Zstr UNPL(in) = StrBegin(&UNPL(buf));                                                                          \
            StrReadFmt(UNPL(in), __VA_ARGS__);                                                                             \
            StrDeinit(&UNPL(buf));                                                                                         \
            Str UNPL(buf) = StrInit();                                                                                     \
            ProcReadFromStderr((p), &UNPL(buf));                                                                           \
            Zstr UNPL(in) = StrBegin(&UNPL(buf));                                                                          \
            StrReadFmt(UNPL(in), __VA_ARGS__);                                                                             \
            StrDeinit(&UNPL(buf));                                                                                         \
    ///
    typedef struct ResolvedSymbol {
        Zstr module_path;
        u64  module_base;
        Zstr symbol_name;
        Zstr module_path;
        u64  module_base;
        Zstr symbol_name;
        u64  symbol_value;
        u64  symbol_size;
        u64  symbol_size;
        u64  offset;
        Zstr source_file;
        Zstr source_dir;
        u32  source_line;
        u64  offset;
        Zstr source_file;
        Zstr source_dir;
        u32  source_line;
        u32  source_column;
    
    typedef struct ResolverCacheEntry {
        Zstr path; // borrowed from ProcMaps.raw
        Elf  elf;
        // Sidecar debug file found via .gnu_debuglink or .note.gnu.build-id.
        ///
        bool dns_resolver_add_path_str(DnsResolver *self, const Str *path);
        bool dns_resolver_add_path_zstr(DnsResolver *self, Zstr path, u64 len);
    #define DnsResolverAddPath(...)          OVERLOAD(DnsResolverAddPath, __VA_ARGS__)
    #define DnsResolverAddPath_2(self, p)    dns_resolver_add_path_str((self), (p))
    
        bool dns_resolver_add_hosts_path_str(DnsResolver *self, const Str *path);
        bool dns_resolver_add_hosts_path_zstr(DnsResolver *self, Zstr path, u64 len);
    #define DnsResolverAddHostsPath(...)          OVERLOAD(DnsResolverAddHostsPath, __VA_ARGS__)
    #define DnsResolverAddHostsPath_2(self, p)    dns_resolver_add_hosts_path_str((self), (p))
    
        bool dns_resolver_add_resolv_path_str(DnsResolver *self, const Str *path);
        bool dns_resolver_add_resolv_path_zstr(DnsResolver *self, Zstr path, u64 len);
    #define DnsResolverAddResolvPath(...)          OVERLOAD(DnsResolverAddResolvPath, __VA_ARGS__)
    #define DnsResolverAddResolvPath_2(self, p)    dns_resolver_add_resolv_path_str((self), (p))
        /// TAGS: Dns, Resolve, API
        ///
        bool dns_resolve_5_zstr(DnsResolver *self, Zstr hostname, u16 port, SocketKind kind, DnsAddrs *out);
        bool dns_resolve_5_str(DnsResolver *self, const Str *hostname, u16 port, SocketKind kind, DnsAddrs *out);
    #define DnsResolve_5(self, hostname, port, kind, out)                                                                  \
            (hostname),                                                                                                    \
            Str *: dns_resolve_5_str((self), (const Str *)(hostname), (port), (kind), (out)),                              \
            Zstr: dns_resolve_5_zstr((self), (Zstr)(hostname), (port), (kind), (out)),                                     \
            char *: dns_resolve_5_zstr((self), (Zstr)(hostname), (port), (kind), (out))                                    \
        )
            Str *: dns_resolve_5_str((self), (const Str *)(hostname), (port), (kind), (out)),                              \
            Zstr: dns_resolve_5_zstr((self), (Zstr)(hostname), (port), (kind), (out)),                                     \
            char *: dns_resolve_5_zstr((self), (Zstr)(hostname), (port), (kind), (out))                                    \
        )
        /// TAGS: Dns, Resolve, API
        ///
        bool dns_resolve_4_vec_zstr(DnsResolver *self, Zstr spec, SocketKind kind, DnsAddrs *out);
        bool dns_resolve_4_vec_str(DnsResolver *self, const Str *spec, SocketKind kind, DnsAddrs *out);
    #define DnsResolve_4_vec(self, spec, kind, out)                                                                        \
            (spec),                                                                                                        \
            Str *: dns_resolve_4_vec_str((self), (const Str *)(spec), (kind), (out)),                                      \
            Zstr: dns_resolve_4_vec_zstr((self), (Zstr)(spec), (kind), (out)),                                             \
            char *: dns_resolve_4_vec_zstr((self), (Zstr)(spec), (kind), (out))                                            \
        )
            Str *: dns_resolve_4_vec_str((self), (const Str *)(spec), (kind), (out)),                                      \
            Zstr: dns_resolve_4_vec_zstr((self), (Zstr)(spec), (kind), (out)),                                             \
            char *: dns_resolve_4_vec_zstr((self), (Zstr)(spec), (kind), (out))                                            \
        )
        /// TAGS: Dns, Resolve, API
        ///
        bool dns_resolve_4_one_zstr(DnsResolver *self, Zstr spec, SocketKind kind, SocketAddr *out);
        bool dns_resolve_4_one_str(DnsResolver *self, const Str *spec, SocketKind kind, SocketAddr *out);
                          (spec),                                                                                          \
                    Str *: dns_resolve_4_vec_str((self), (const Str *)(spec), (kind), (DnsAddrs *)(out)),                  \
                    Zstr: dns_resolve_4_vec_zstr((self), (Zstr)(spec), (kind), (DnsAddrs *)(out)),                         \
                    char *: dns_resolve_4_vec_zstr((self), (Zstr)(spec), (kind), (DnsAddrs *)(out))                        \
                      ),                                                                                                   \
                    Str *: dns_resolve_4_vec_str((self), (const Str *)(spec), (kind), (DnsAddrs *)(out)),                  \
                    Zstr: dns_resolve_4_vec_zstr((self), (Zstr)(spec), (kind), (DnsAddrs *)(out)),                         \
                    char *: dns_resolve_4_vec_zstr((self), (Zstr)(spec), (kind), (DnsAddrs *)(out))                        \
                      ),                                                                                                   \
            SocketAddr *: _Generic(                                                                                        \
                            (spec),                                                                                        \
                    Str *: dns_resolve_4_one_str((self), (const Str *)(spec), (kind), (SocketAddr *)(out)),                \
                    Zstr: dns_resolve_4_one_zstr((self), (Zstr)(spec), (kind), (SocketAddr *)(out)),                       \
                    char *: dns_resolve_4_one_zstr((self), (Zstr)(spec), (kind), (SocketAddr *)(out))                      \
                        )                                                                                                  \
                    Str *: dns_resolve_4_one_str((self), (const Str *)(spec), (kind), (SocketAddr *)(out)),                \
                    Zstr: dns_resolve_4_one_zstr((self), (Zstr)(spec), (kind), (SocketAddr *)(out)),                       \
                    char *: dns_resolve_4_one_zstr((self), (Zstr)(spec), (kind), (SocketAddr *)(out))                      \
                        )                                                                                                  \
        )
    bool macho_cache_resolve_zstr(
        MachoCache *self,
        Zstr module_path,
        u64         slide,
        u64         runtime_ip,
        u64         slide,
        u64         runtime_ip,
        Zstr *out_name,
        u32        *out_offset
    );
        u64         slide,
        u64         runtime_ip,
        Zstr *out_name,
        u32        *out_offset
    );
            (module_path),                                                                                                 \
            Str *: macho_cache_resolve_str((self), (const Str *)(module_path), (slide), (runtime_ip), (out_name), (out_offset)),  \
            Zstr: macho_cache_resolve_zstr((self), (Zstr)(module_path), (slide), (runtime_ip), (out_name), (out_offset)),  \
            char *: macho_cache_resolve_zstr((self), (Zstr)(module_path), (slide), (runtime_ip), (out_name), (out_offset)) \
        )
            Str *: macho_cache_resolve_str((self), (const Str *)(module_path), (slide), (runtime_ip), (out_name), (out_offset)),  \
            Zstr: macho_cache_resolve_zstr((self), (Zstr)(module_path), (slide), (runtime_ip), (out_name), (out_offset)),  \
            char *: macho_cache_resolve_zstr((self), (Zstr)(module_path), (slide), (runtime_ip), (out_name), (out_offset)) \
        )
    /// TAGS: Http, Find, Header
    ///
    HttpHeader *http_headers_find_zstr(HttpHeaders *headers, Zstr key);
    HttpHeader *http_headers_find_str(HttpHeaders *headers, const Str *key);
    #define HttpHeadersFind(headers, key)                                                                                  \
    HttpHeader *http_headers_find_str(HttpHeaders *headers, const Str *key);
    #define HttpHeadersFind(headers, key)                                                                                  \
        _Generic((key), Str *: http_headers_find_str, Zstr: http_headers_find_zstr, char *: http_headers_find_zstr)(       \
            (headers),                                                                                                     \
            (key)                                                                                                          \
            (in),                                                                                                          \
            Str *: http_request_parse_str((req), (const Str *)(in)),                                                       \
            Zstr: http_request_parse_zstr((req), (Zstr)(in)),                                                              \
            char *: http_request_parse_zstr((req), (Zstr)(in))                                                             \
        )
            Str *: http_request_parse_str((req), (const Str *)(in)),                                                       \
            Zstr: http_request_parse_zstr((req), (Zstr)(in)),                                                              \
            char *: http_request_parse_zstr((req), (Zstr)(in))                                                             \
        )
    /// TAGS: Http, ResponseCode, Response, Convert, Zstr
    ///
    Zstr HttpResponseCodeToZstr(HttpResponseCode code);
    Zstr HttpContentTypeToZstr(HttpContentType content_type);
    ///
    Zstr HttpResponseCodeToZstr(HttpResponseCode code);
    Zstr HttpContentTypeToZstr(HttpContentType content_type);
    
    ///
                (filepath),                                                                                                \
                Str *: http_respond_with_file_str((response), (status), (content_type), (const Str *)(filepath)),          \
                Zstr: http_respond_with_file_zstr((response), (status), (content_type), (Zstr)(filepath)),                 \
                char *: http_respond_with_file_zstr((response), (status), (content_type), (Zstr)(filepath))                \
            )
                Str *: http_respond_with_file_str((response), (status), (content_type), (const Str *)(filepath)),          \
                Zstr: http_respond_with_file_zstr((response), (status), (content_type), (Zstr)(filepath)),                 \
                char *: http_respond_with_file_zstr((response), (status), (content_type), (Zstr)(filepath))                \
            )
    #endif
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Utility/StrIter.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
    ///
    #define KvConfigGet(cfg, key)                                                                                          \
        _Generic((key), Str *: kvconfig_get_str, Zstr: kvconfig_get_zstr, char *: kvconfig_get_zstr)((cfg), (key))
    
    ///
    ///
    #define KvConfigGetPtr(cfg, key)                                                                                       \
        _Generic((key), Str *: kvconfig_get_ptr_str, Zstr: kvconfig_get_ptr_zstr, char *: kvconfig_get_ptr_zstr)(          \
            (cfg),                                                                                                         \
            (key)                                                                                                          \
    ///
    #define KvConfigContains(cfg, key)                                                                                     \
        _Generic((key), Str *: kvconfig_contains_str, Zstr: kvconfig_contains_zstr, char *: kvconfig_contains_zstr)(       \
            (cfg),                                                                                                         \
            (key)                                                                                                          \
    ///
    #define KvConfigGetBool(cfg, key, value)                                                                               \
        _Generic((key), Str *: kvconfig_get_bool_str, Zstr: kvconfig_get_bool_zstr, char *: kvconfig_get_bool_zstr)(       \
            (cfg),                                                                                                         \
            (key),                                                                                                         \
    ///
    #define KvConfigGetI64(cfg, key, value)                                                                                \
        _Generic((key), Str *: kvconfig_get_i64_str, Zstr: kvconfig_get_i64_zstr, char *: kvconfig_get_i64_zstr)(          \
            (cfg),                                                                                                         \
            (key),                                                                                                         \
    ///
    #define KvConfigGetF64(cfg, key, value)                                                                                \
        _Generic((key), Str *: kvconfig_get_f64_str, Zstr: kvconfig_get_f64_zstr, char *: kvconfig_get_f64_zstr)(          \
            (cfg),                                                                                                         \
            (key),                                                                                                         \
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
        u32  rva;
        u32  size;
        Zstr name;
    } PdbFunction;
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: pdb_open((out), (Zstr)StrBegin((Str *)(path)), MisraScope),                                             \
            Zstr: pdb_open((out), (Zstr)(path), MisraScope),                                                               \
            char *: pdb_open((out), (Zstr)(path), MisraScope)                                                              \
            (path),                                                                                                        \
            Str *: pdb_open((out), (Zstr)StrBegin((Str *)(path)), MisraScope),                                             \
            Zstr: pdb_open((out), (Zstr)(path), MisraScope),                                                               \
            char *: pdb_open((out), (Zstr)(path), MisraScope)                                                              \
        )
            Str *: pdb_open((out), (Zstr)StrBegin((Str *)(path)), MisraScope),                                             \
            Zstr: pdb_open((out), (Zstr)(path), MisraScope),                                                               \
            char *: pdb_open((out), (Zstr)(path), MisraScope)                                                              \
        )
    #define PdbOpen_3(out, path, alloc)                                                                                    \
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: pdb_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                    \
            Zstr: pdb_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                      \
            char *: pdb_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                     \
            (path),                                                                                                        \
            Str *: pdb_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                    \
            Zstr: pdb_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                      \
            char *: pdb_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                     \
        )
            Str *: pdb_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                    \
            Zstr: pdb_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                      \
            char *: pdb_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                     \
        )
    typedef struct DwarfLineEntry {
        u64  address;
        Zstr file;
        Zstr dir;
        u32  line;
        u64  address;
        Zstr file;
        Zstr dir;
        u32  line;
        u32  column;
        u64  low_pc;  // file-relative virtual address (same space as ElfSymbol.value)
        u64  high_pc; // exclusive end
        Zstr name;    // borrowed from `string_pool`
    } DwarfFunction;
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
    ///
    typedef struct ElfSection {
        Zstr name;
        u32  type;       // ElfSectionType plus arch-specific extensions
        u64  flags;
    ///
    typedef struct ElfSymbol {
        Zstr          name;
        ElfSymbolBind bind;
        ElfSymbolType type;
        const u8   *build_id;
        u32         build_id_size;
        Zstr        debuglink_name;
        u32         debuglink_crc;
    } Elf;
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: elf_open((out), (Zstr)StrBegin((Str *)(path)), MisraScope),                                             \
            Zstr: elf_open((out), (Zstr)(path), MisraScope),                                                               \
            char *: elf_open((out), (Zstr)(path), MisraScope)                                                              \
            (path),                                                                                                        \
            Str *: elf_open((out), (Zstr)StrBegin((Str *)(path)), MisraScope),                                             \
            Zstr: elf_open((out), (Zstr)(path), MisraScope),                                                               \
            char *: elf_open((out), (Zstr)(path), MisraScope)                                                              \
        )
            Str *: elf_open((out), (Zstr)StrBegin((Str *)(path)), MisraScope),                                             \
            Zstr: elf_open((out), (Zstr)(path), MisraScope),                                                               \
            char *: elf_open((out), (Zstr)(path), MisraScope)                                                              \
        )
    #define ElfOpen_3(out, path, alloc)                                                                                    \
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: elf_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                    \
            Zstr: elf_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                      \
            char *: elf_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                     \
            (path),                                                                                                        \
            Str *: elf_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                    \
            Zstr: elf_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                      \
            char *: elf_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                     \
        )
            Str *: elf_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                    \
            Zstr: elf_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                      \
            char *: elf_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                     \
        )
    ///
    #define ElfFindSection(self, name)                                                                                     \
        _Generic((name), Str *: elf_find_section_str, Zstr: elf_find_section_zstr, char *: elf_find_section_zstr)(         \
            (self),                                                                                                        \
            (name)                                                                                                         \
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
        u8   guid[16];
        u32  age;
        Zstr pdb_path;
    } PeCodeViewInfo;
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: pe_open((out), (Zstr)StrBegin((Str *)(path)), MisraScope),                                              \
            Zstr: pe_open((out), (Zstr)(path), MisraScope),                                                                \
            char *: pe_open((out), (Zstr)(path), MisraScope)                                                               \
            (path),                                                                                                        \
            Str *: pe_open((out), (Zstr)StrBegin((Str *)(path)), MisraScope),                                              \
            Zstr: pe_open((out), (Zstr)(path), MisraScope),                                                                \
            char *: pe_open((out), (Zstr)(path), MisraScope)                                                               \
        )
            Str *: pe_open((out), (Zstr)StrBegin((Str *)(path)), MisraScope),                                              \
            Zstr: pe_open((out), (Zstr)(path), MisraScope),                                                                \
            char *: pe_open((out), (Zstr)(path), MisraScope)                                                               \
        )
    #define PeOpen_3(out, path, alloc)                                                                                     \
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: pe_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                     \
            Zstr: pe_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                       \
            char *: pe_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                      \
            (path),                                                                                                        \
            Str *: pe_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                     \
            Zstr: pe_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                       \
            char *: pe_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                      \
        )
            Str *: pe_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                     \
            Zstr: pe_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                       \
            char *: pe_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                      \
        )
    ///
    #define PeFindSection(self, name)                                                                                      \
        _Generic((name), Str *: pe_find_section_str, Zstr: pe_find_section_zstr, char *: pe_find_section_zstr)(            \
            (self),                                                                                                        \
            (name)                                                                                                         \
                StrPushBackR(&(j), ',');                                                                                   \
            }                                                                                                              \
            StrAppendFmt(&(j), "\"{}\":", (Zstr)(k));                                                                      \
            JW_OBJ(j, writer);                                                                                             \
        } while (0)
                StrPushBackR(&(j), ',');                                                                                   \
            }                                                                                                              \
            StrAppendFmt(&(j), "\"{}\":", (Zstr)(k));                                                                      \
            JW_ARR(j, arr, item, writer);                                                                                  \
        } while (0)
                StrPushBackR(&(j), ',');                                                                                   \
            }                                                                                                              \
            StrAppendFmt(&(j), "\"{}\":", (Zstr)(k));                                                                      \
            JW_INT(j, i);                                                                                                  \
        } while (0)
                StrPushBackR(&(j), ',');                                                                                   \
            }                                                                                                              \
            StrAppendFmt(&(j), "\"{}\":", (Zstr)(k));                                                                      \
            JW_FLT(j, f);                                                                                                  \
        } while (0)
            const Str *UNPL(jw_s)   = &(s);                                                                                \
            u64        UNPL(jw_len) = StrLen(UNPL(jw_s));                                                                  \
            StrAppendFmt(&(j), "\"{}\"", UNPL(jw_len) ? (Zstr)StrBegin(UNPL(jw_s)) : (Zstr) "");                           \
        } while (0)
                StrPushBackR(&(j), ',');                                                                                   \
            }                                                                                                              \
            StrAppendFmt(&(j), "\"{}\":", (Zstr)(k));                                                                      \
            JW_STR(j, s);                                                                                                  \
        } while (0)
    #define JW_BOOL(j, b)                                                                                                  \
        do {                                                                                                               \
            StrAppendFmt(&(j), "{}", (Zstr)((b) ? "true" : "false"));                                                      \
        } while (0)
                StrPushBackR(&(j), ',');                                                                                   \
            }                                                                                                              \
            StrAppendFmt(&(j), "\"{}\":", (Zstr)(k));                                                                      \
            JW_BOOL(j, b);                                                                                                 \
        } while (0)
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
    ///
    typedef struct MachoSymbol {
        Zstr name;
        u64  value;         // virtual address
        u8   type;          // n_type bitfield
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: macho_open((out), (Zstr)StrBegin((Str *)(path)), MisraScope),                                           \
            Zstr: macho_open((out), (Zstr)(path), MisraScope),                                                             \
            char *: macho_open((out), (Zstr)(path), MisraScope)                                                            \
            (path),                                                                                                        \
            Str *: macho_open((out), (Zstr)StrBegin((Str *)(path)), MisraScope),                                           \
            Zstr: macho_open((out), (Zstr)(path), MisraScope),                                                             \
            char *: macho_open((out), (Zstr)(path), MisraScope)                                                            \
        )
            Str *: macho_open((out), (Zstr)StrBegin((Str *)(path)), MisraScope),                                           \
            Zstr: macho_open((out), (Zstr)(path), MisraScope),                                                             \
            char *: macho_open((out), (Zstr)(path), MisraScope)                                                            \
        )
    #define MachoOpen_3(out, path, alloc)                                                                                  \
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: macho_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                  \
            Zstr: macho_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                    \
            char *: macho_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                   \
            (path),                                                                                                        \
            Str *: macho_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                  \
            Zstr: macho_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                    \
            char *: macho_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                   \
        )
            Str *: macho_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                  \
            Zstr: macho_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                    \
            char *: macho_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                   \
        )
        macho_find_section(                                                                                                \
            (self),                                                                                                        \
            _Generic((segment), Str *: (Zstr)StrBegin((Str *)(segment)), Zstr: (Zstr)(segment), char *: (Zstr)(segment)),  \
            _Generic((section), Str *: (Zstr)StrBegin((Str *)(section)), Zstr: (Zstr)(section), char *: (Zstr)(section))   \
        )
            (self),                                                                                                        \
            _Generic((segment), Str *: (Zstr)StrBegin((Str *)(segment)), Zstr: (Zstr)(segment), char *: (Zstr)(segment)),  \
            _Generic((section), Str *: (Zstr)StrBegin((Str *)(section)), Zstr: (Zstr)(section), char *: (Zstr)(section))   \
        )
            (name),                                                                                                        \
            Str *: dns_build_query_str((out), (id), (const Str *)(name), (type)),                                          \
            Zstr: dns_build_query_zstr((out), (id), (Zstr)(name), (type)),                                                 \
            char *: dns_build_query_zstr((out), (id), (Zstr)(name), (type))                                                \
        )
            Str *: dns_build_query_str((out), (id), (const Str *)(name), (type)),                                          \
            Zstr: dns_build_query_zstr((out), (id), (Zstr)(name), (type)),                                                 \
            char *: dns_build_query_zstr((out), (id), (Zstr)(name), (type))                                                \
        )
        u32  perms;       // bitmask of ProcMapPerms
        u64  file_offset; // offset within the backing file
        Zstr path;        // backing file path, or "" if anonymous
    } ProcMapEntry;
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Log.h>
    #include <Misra/Std/Zstr.h>
    
    // Copy function for char* - duplicates the string. Signature must match
    
    #include <Misra/Config.h>
    #include <Misra/Std/Zstr.h>
    
    #if PLATFORM_WINDOWS
    //     without libc). Same `__imp_<name>` indirect-call convention as
    //     `__stdio_common_vsprintf` above.
    static char *getenv_stub(Zstr name) {
        (void)name;
        return ((char *)0);
    // (UCRT) maps most of them to the same values; the ones it diverges
    // on don't matter for our call sites today.
    static Zstr errno_description(i32 eno) {
        switch (eno) {
    #ifdef EPERM
    char **envp_global = NULL;
    #elif PLATFORM_WINDOWS
    __declspec(dllimport) extern char *__cdecl getenv(Zstr name);
    #endif
    #endif
    
    Zstr EnvGet(Zstr name) {
        if (!name) {
            return NULL;
        // Match `name` against the prefix of each entry up to '='.
        for (char **e = envp_global; *e; ++e) {
            Zstr entry = *e;
            Zstr n     = name;
            while (*n && *entry == *n) {
        for (char **e = envp_global; *e; ++e) {
            Zstr entry = *e;
            Zstr n     = name;
            while (*n && *entry == *n) {
                ++entry;
        return NULL;
    #elif PLATFORM_WINDOWS
        return (Zstr)getenv(name);
    #elif PLATFORM_DARWIN
        // No libSystem `_getenv` reference -- callers must capture envp
    #endif
    
    void LogWrite(LogMessageType type, Zstr tag, u64 line, Zstr msg) {
        if (!msg) {
            return;
        }
    
        static Zstr NAMES[] = {
            [LOG_MESSAGE_TYPE_FATAL] = "FATAL",
            [LOG_MESSAGE_TYPE_ERROR] = "ERROR",
        HeapAllocator h    = HeapAllocatorInit();
        Str           full = StrInit(&h);
        StrAppendFmt(&full, "[{}] [{}:{}] {}\n", (Zstr)NAMES[type], (Zstr)tag, line, (Zstr)msg);
    
        File out = (type == LOG_MESSAGE_TYPE_INFO) ? FileFromFd(1) : FileFromFd(2);
    // in higher-level code, not at the syscall boundary. Returns false if
    // the mode is malformed.
    static bool parse_open_mode(Zstr mode, int *out_flags) {
    #if PLATFORM_WINDOWS
        (void)mode;
        char primary = mode[0];
        bool plus    = false;
        for (Zstr p = mode + 1; *p; ++p) {
            if (*p == '+') {
                plus = true;
    // ---------------------------------------------------------------------------
    
    File file_open(Zstr path, Zstr mode) {
        File f = {0};
    #if PLATFORM_WINDOWS
        DWORD disposition = OPEN_EXISTING;
        bool  plus        = false;
        for (Zstr p = mode + 1; *p; ++p) {
            if (*p == '+')
                plus = true;
    
    #include <Misra/Std/ArgParse.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/File.h>
    #include <Misra/Std/Io.h>
    // Human-readable type name used in invalid-value error messages. Lines
    // up 1:1 with the ArgKind enum; new entries get a label here.
    static Zstr arg_kind_label(ArgKind k) {
        switch (k) {
            case ARG_KIND_ZSTR :
    }
    
    static bool zstr_eq(Zstr a, Zstr b) {
        return a && b && ZstrCompare(a, b) == 0;
    }
    // Returns false on empty input, non-digit content, or trailing junk.
    // Signed range checked against the caller-supplied lo/hi.
    static bool parse_signed(Zstr s, i64 lo, i64 hi, i64 *out) {
        if (!s || !*s)
            return false;
        if (!s || !*s)
            return false;
        Zstr end = NULL;
        i64  v   = ZstrToI64(s, &end);
        if (!end || end == s || *end != '\0')
    // Same shape, unsigned. ZstrToI64 doesn't span the unsigned-64 range
    // past 0x7fffffffffffffff so we walk decimal digits ourselves.
    static bool parse_unsigned(Zstr s, u64 hi, u64 *out) {
        if (!s || !*s)
            return false;
    }
    
    static bool parse_bool(Zstr s, bool *out) {
        if (zstr_eq(s, "true") || zstr_eq(s, "1") || zstr_eq(s, "yes") || zstr_eq(s, "on")) {
            *out = true;
    }
    
    static bool parse_f64_full(Zstr s, f64 *out) {
        if (!s || !*s)
            return false;
        if (!s || !*s)
            return false;
        Zstr end = NULL;
        f64  v   = ZstrToF64(s, &end);
        if (!end || end == s || *end != '\0')
    // false on type-mismatch / out-of-range so the caller can emit a
    // "invalid value 'X' for --flag: expected <type>" message.
    static bool store_value(ArgKind kind, void *target, Zstr value) {
        switch (kind) {
            case ARG_KIND_ZSTR : {
        switch (kind) {
            case ARG_KIND_ZSTR : {
                *(Zstr *)target = value;
                return true;
            }
    // ---------------------------------------------------------------------------
    
    static ArgSpec *find_long(ArgParse *self, Zstr long_name) {
        VecForeachPtr(&self->specs, sp) {
            if (sp->role == ARG_ROLE_POSITIONAL)
    }
    
    static ArgSpec *find_short(ArgParse *self, Zstr short_name) {
        VecForeachPtr(&self->specs, sp) {
            if (sp->role == ARG_ROLE_POSITIONAL)
    // short-only options without a long form we fall back to "VALUE".
    static void append_metavar(Str *out, const ArgSpec *sp) {
        Zstr src = sp->long_name;
        if (!src) {
            StrPushBackMany(out, "VALUE");
    // ---------------------------------------------------------------------------
    
    void arg_register(ArgParse *self, ArgRole role, Zstr short_name, Zstr long_name, Zstr help, ArgTarget target) {
        if (!self)
            LOG_FATAL("arg_register: NULL parser");
    static ArgRun handle_option_token(
        ArgParse *self,
        Zstr      tok,
        int      *i_io, // walked forward by 1 when we consume a value
        int       argc,
    ) {
        bool is_long  = (tok[0] == '-' && tok[1] == '-');
        Zstr eq       = NULL;
        Zstr inline_v = NULL;
        bool is_long  = (tok[0] == '-' && tok[1] == '-');
        Zstr eq       = NULL;
        Zstr inline_v = NULL;
    
        if (is_long) {
        ArgRun result = ARG_RUN_ERROR;
        StrInitStack(flagbuf, 128) {
            Zstr flag = tok;
            if (eq) {
                u64 n = (u64)(eq - tok);
                case ARG_ROLE_REQUIRED :
                case ARG_ROLE_OPTIONAL : {
                    Zstr val = inline_v;
                    if (!val) {
                        if (*i_io + 1 >= argc) {
    // when -v is a Flag or a Count. -lFOO (stuck value) is intentionally
    // not supported in v1.
    static ArgRun handle_short_bundle(ArgParse *self, Zstr tok, File *err) {
        // tok looks like "-XYZ..."; verify every char maps to a Flag/Count.
        ArgRun result = ARG_RUN_OK;
        // tok looks like "-XYZ..."; verify every char maps to a Flag/Count.
        ArgRun result = ARG_RUN_OK;
        for (Zstr p = tok + 1; *p; ++p) {
            bool iter_ok = false;
            StrInitStack(buf, 3) {
                StrResize(&buf, 2);
    
                ArgSpec *sp = find_short(self, (Zstr)data);
                if (!sp) {
                    FWriteFmtLn(err, "{}: unknown option: {}", self->name, (Zstr)data);
                ArgSpec *sp = find_short(self, (Zstr)data);
                if (!sp) {
                    FWriteFmtLn(err, "{}: unknown option: {}", self->name, (Zstr)data);
                    break;
                }
                    sp->seen = true;
                } else {
                    FWriteFmtLn(err, "{}: option {} requires a value, can't bundle", self->name, (Zstr)data);
                    break;
                }
    
        for (int i = 1; i < argc; ++i) {
            Zstr tok = argv[i];
    
            if (!rest_positional) {
                            StrResize(&two, 2);
    
                            ArgSpec *first = find_short(self, (Zstr)data);
                            if (first && (first->role == ARG_ROLE_FLAG || first->role == ARG_ROLE_COUNT)) {
                                decision = BUNDLE_TRY;
                                    "{}: short value option '{}' cannot be bundled; use form '{} VAL' or '{}=VAL'",
                                    self->name,
                                    (Zstr)data,
                                    (Zstr)data,
                                    (Zstr)data
                                    self->name,
                                    (Zstr)data,
                                    (Zstr)data,
                                    (Zstr)data
                                );
                                    (Zstr)data,
                                    (Zstr)data,
                                    (Zstr)data
                                );
                            }
    #include <Misra/Std/Log.h>
    #include <Misra/Std/Memory.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Sys.h>
    #include <Misra/Types.h>
    static bool _write_r64(Str *o, FmtInfo *fmt_info, u64 *v);
    
    static Zstr _read_r8(Zstr i, FmtInfo *fmt_info, u8 *v);
    static Zstr _read_r16(Zstr i, FmtInfo *fmt_info, u16 *v);
    static Zstr _read_r32(Zstr i, FmtInfo *fmt_info, u32 *v);
    
    static Zstr _read_r8(Zstr i, FmtInfo *fmt_info, u8 *v);
    static Zstr _read_r16(Zstr i, FmtInfo *fmt_info, u16 *v);
    static Zstr _read_r32(Zstr i, FmtInfo *fmt_info, u32 *v);
    static Zstr _read_r64(Zstr i, FmtInfo *fmt_info, u64 *v);
    static Zstr _read_r8(Zstr i, FmtInfo *fmt_info, u8 *v);
    static Zstr _read_r16(Zstr i, FmtInfo *fmt_info, u16 *v);
    static Zstr _read_r32(Zstr i, FmtInfo *fmt_info, u32 *v);
    static Zstr _read_r64(Zstr i, FmtInfo *fmt_info, u64 *v);
    static Zstr _read_r16(Zstr i, FmtInfo *fmt_info, u16 *v);
    static Zstr _read_r32(Zstr i, FmtInfo *fmt_info, u32 *v);
    static Zstr _read_r64(Zstr i, FmtInfo *fmt_info, u64 *v);
    
    // Avoids `__builtin_clzll`: we'd need a separate MSVC branch via
    // any base prefix; type is one of `c`/`a`/`A`/`x`/`X`/`b`/`o`/`r`/`e`/
    // `E`/`s`.
    static bool parse_format_spec(Zstr spec, u32 len, FmtInfo *fi) {
        if (!spec || !fi) {
            LOG_FATAL("Invalid arguments");
    }
    
    bool str_append_fmt(Str *o, Zstr fmt, TypeSpecificIO *args, u64 argc) {
        if (!o || !fmt) {
            LOG_FATAL("Invalid arguments");
    }
    
    bool str_write_fmt(Str *o, Zstr fmt, TypeSpecificIO *args, u64 argc) {
        if (!o || !fmt) {
            LOG_FATAL("Invalid arguments");
    }
    
    bool str_patch_fmt(Str *o, size offset, Zstr fmt, TypeSpecificIO *args, u64 argc) {
        if (!o || !fmt) {
            LOG_FATAL("Invalid arguments");
    }
    
    bool f_write_fmt(File *stream, Zstr fmtstr, TypeSpecificIO *argv, u64 argc, bool append_newline) {
        Str  out;
        bool ok = true;
    }
    
    Zstr str_read_fmt(Zstr input, Zstr fmtstr, TypeSpecificIO *argv, u64 argc) {
        if (!input || !fmtstr) {
            LOG_FATAL("Invalid arguments");
        }
    
        Zstr p         = fmtstr;
        Zstr in        = input;
        u64  rem_p     = ZstrLen(fmtstr);
    
        Zstr p         = fmtstr;
        Zstr in        = input;
        u64  rem_p     = ZstrLen(fmtstr);
        u64  rem_in    = ZstrLen(in);
                rem_p--;
    
                Zstr start    = p;
                size spec_len = 0;
                while (rem_p > 0 && *p != '}') {
                // table instead of the type-specific reader the caller
                // registered.
                Zstr               next       = NULL;
                TypeSpecificReader raw_reader = NULL;
                if (fmt_info.flags & FMT_FLAG_RAW) {
    
                    if (space_len) {
                        Zstr e = NULL;
                        if ((e = ZstrFindSubstringN(in, p, space_len))) {
                            fmt_info.max_read_len = e - in;
    // ---------------------------------------------------------------------------
    
    bool buf_read_fmt(BufIter *iter, Zstr fmtstr, TypeSpecificIO *argv, u64 argc) {
        if (!iter || !fmtstr) {
            LOG_FATAL("buf_read_fmt: NULL iter or fmtstr");
            }
            StrIter spec_start_fsi = fsi;
            Zstr    spec_start     = (Zstr)StrIterPos(&fsi);
            char    sc             = 0;
            while (StrIterPeek(&fsi, &sc) && sc != '}') {
    
            // Read the raw bytes into a u64 with the spec's endianness.
            Zstr in   = (Zstr)IterPos(iter);
            u64  x    = 0;
            Zstr next = NULL;
            Zstr in   = (Zstr)IterPos(iter);
            u64  x    = 0;
            Zstr next = NULL;
            switch (fmt_info.width) {
                case 1 : {
    // ultimately writes into. Shared between buf_append_fmt and the body
    // rendering done by buf_write_fmt / buf_patch_fmt.
    static bool render_binary_fmt(Str *out, Zstr fmtstr, TypeSpecificIO *argv, u64 argc) {
        u64     arg_index = 0;
        StrIter fsi       = StrIterFromZstr(fmtstr);
            }
            StrIter spec_start_fsi = fsi;
            Zstr    spec_start     = (Zstr)StrIterPos(&fsi);
            char    sc             = 0;
            while (StrIterPeek(&fsi, &sc) && sc != '}') {
    }
    
    bool buf_append_fmt(Buf *out, Zstr fmtstr, TypeSpecificIO *argv, u64 argc) {
        if (!out || !fmtstr) {
            LOG_FATAL("buf_append_fmt: NULL out or fmtstr");
    }
    
    bool buf_write_fmt(Buf *out, Zstr fmtstr, TypeSpecificIO *argv, u64 argc) {
        if (!out || !fmtstr) {
            LOG_FATAL("buf_write_fmt: NULL out or fmtstr");
    }
    
    bool buf_patch_fmt(Buf *out, size offset, Zstr fmtstr, TypeSpecificIO *argv, u64 argc) {
        if (!out || !fmtstr) {
            LOG_FATAL("buf_patch_fmt: NULL out or fmtstr");
    }
    
    void f_read_fmt(File *file, Zstr fmtstr, TypeSpecificIO *argv, u64 argc) {
        // DefaultAllocator: the slurp buffer below sizes itself from file length
        // (potentially many MiB on seekable inputs), so no stack-bound applies.
    
            if (StrLen(&buffer)) {
                Zstr new_pos = str_read_fmt(StrBegin(&buffer), fmtstr, argv, argc);
                if (!new_pos) {
                    LOG_ERROR("Parse failed, rolling back...");
    }
    
    static inline bool write_char_internal(Str *o, FormatFlags flags, Zstr vs, size len) {
        if (!o || !vs || !len) {
            LOG_FATAL("Invalid arguments");
    
        {
            Zstr body   = StrBegin(&canonical);
            Zstr dot    = NULL;
            u64  prefix = 0;
        {
            Zstr body   = StrBegin(&canonical);
            Zstr dot    = NULL;
            u64  prefix = 0;
            u64  frac   = 0;
    }
    
    static size float_fmt_token_length(Zstr input) {
        size pos            = 0;
        bool saw_digit      = false;
    // post-read cursor so the outer reader can splice it back into the
    // surrounding format-walk.
    static inline Zstr read_chars_internal(Zstr i, u8 *buffer, size buffer_size, FmtInfo *fmt_info) {
        if (!i || !buffer || !buffer_size) {
            LOG_FATAL("Invalid arguments");
    
        size bytes_read = 0;
        Zstr current    = i;
        bool force_case = fmt_info && (fmt_info->flags & FMT_FLAG_FORCE_CASE) != 0;
        bool is_caps    = fmt_info && (fmt_info->flags & FMT_FLAG_CAPS) != 0;
        return _write_Str(o, fmt_info, (Str *)b);
    }
    Zstr _read_Buf(Zstr i, FmtInfo *fmt_info, Buf *b) {
        return _read_Str(i, fmt_info, (Str *)b);
    }
    }
    
    Zstr _read_DateTime(Zstr i, FmtInfo *fmt_info, DateTime *dt) {
        (void)fmt_info;
        if (!i || !dt) {
            LOG_FATAL("Invalid arguments");
        }
        Zstr p    = i;
        i32  year = 0;
        u32  mon = 0, day = 0, hh = 0, mm = 0, ss = 0;
        if (*p == '.') {
            p++;
            Zstr frac_at = p;
            StrReadFmt(p, "{}", nanos);
            if (p == frac_at) {
        } else if (*p == '+' || *p == '-') {
            i32  sign   = (*p == '-') ? -1 : 1;
            Zstr off_at = ++p;
            u32  oh = 0, om = 0;
            StrReadFmt(p, "{}:{}", oh, om);
    
                if (fmt_info->flags & FMT_FLAG_CHAR) {
                    if (!write_char_internal(o, fmt_info->flags, (Zstr)StrBegin(s), len)) {
                        return false;
                    }
                            }
                        } else {
                            Zstr digits = "0123456789abcdef";
                            if (!StrPushBackMany(o, "\\x") || !StrPushBackR(o, digits[(c >> 4) & 0xf]) ||
                                !StrPushBackR(o, digits[c & 0xf])) {
    }
    
    bool _write_Zstr(Str *o, FmtInfo *fmt_info, Zstr *s) {
        if (!o || !s || !*s || !fmt_info) {
            LOG_FATAL("Invalid arguments");
        // size of just-this-field, not the accumulated buffer.
        size start_len = StrLen(o);
        Zstr xs        = *s;
    
        // Empty Zstr: skip the body and fall straight through to padding.
                            }
                        } else {
                            Zstr digits = "0123456789abcdef";
                            if (!StrPushBackMany(o, "\\x") || !StrPushBackR(o, digits[(xs[i] >> 4) & 0xf]) ||
                                !StrPushBackR(o, digits[xs[i] & 0xf])) {
    
    bool _write_ZstrAlloc(Str *o, FmtInfo *fmt_info, ZstrIOArg *arg) {
        Zstr *value = NULL;
    
        if (!arg) {
        }
    
        value = (Zstr *)arg->value;
        return _write_Zstr(o, fmt_info, value);
    }
    #endif // FEATURE_FLOAT
    
    char ZstrProcessEscape(Zstr *str) {
        if (!str || !*str)
            return 0;
            return 0;
    
        Zstr s = *str;
        if (*s != '\\') {
            LOG_ERROR("ZstrProcessEscape called on non-escape sequence");
    }
    
    Zstr _read_Str(Zstr i, FmtInfo *fmt_info, Str *s) {
        if (!i || !s)
            LOG_FATAL("Invalid arguments");
            if (quote) {
                if (*i == '\\') {
                    Zstr curr = i;
                    char c    = ZstrProcessEscape(&curr);
                    if (c == 0) {
    
                if (*i == '\\') {
                    Zstr curr = i;
                    char c    = ZstrProcessEscape(&curr);
                    if (c == 0) {
    // ---------------------------------------------------------------------------
    
    Zstr _read_f64(Zstr i, FmtInfo *fmt_info, f64 *v) {
        DefaultAllocator scratch = DefaultAllocatorInit();
        if (fmt_info && (fmt_info->flags & FMT_FLAG_CHAR)) {
            u64  temp = 0;
            Zstr next = read_chars_internal(i, (u8 *)&temp, sizeof(temp), fmt_info);
            *v        = (f64)temp;
            DefaultAllocatorDeinit(&scratch);
        if ((c == 'i' || c == 'I' || c == 'n' || c == 'N') || (c == '-' && (c1 == 'i' || c1 == 'I'))) {
            StrIter saved = si;
            Zstr    start = StrIterDataAt(&si, StrIterIndex(&si));
            while (StrIterPeek(&si, &c) && !IS_SPACE(c)) {
                StrIterMustNext(&si);
        }
    
        Zstr start = StrIterDataAt(&si, StrIterIndex(&saved));
        size pos   = StrIterIndex(&si) - StrIterIndex(&saved);
    }
    
    Zstr _read_u8(Zstr i, FmtInfo *fmt_info, u8 *v) {
        DefaultAllocator scratch = DefaultAllocatorInit();
    
        if (fmt_info && (fmt_info->flags & FMT_FLAG_CHAR)) {
            Zstr next = read_chars_internal(StrIterDataAt(&si, StrIterIndex(&si)), (u8 *)v, sizeof(*v), fmt_info);
            DefaultAllocatorDeinit(&scratch);
            return next;
        }
    
        Zstr start = StrIterDataAt(&si, StrIterIndex(&saved));
        size pos   = StrIterIndex(&si) - StrIterIndex(&saved);
    // ---------------------------------------------------------------------------
    #define _MAKE_READ_TXT_INT(NAME, T, VAL_T, PARSER, BOUND_CHECK)                                                        \
        Zstr _read_##NAME(Zstr i, FmtInfo *fmt_info, T *v) {                                                               \
            DefaultAllocator scratch = DefaultAllocatorInit();                                                             \
                                                                                                                           \
            if (fmt_info && (fmt_info->flags & FMT_FLAG_CHAR)) {                                                           \
                *v        = 0;                                                                                             \
                Zstr next = read_chars_internal(i, (u8 *)v, sizeof(*v), fmt_info);                                         \
                DefaultAllocatorDeinit(&scratch);                                                                          \
                return next;                                                                                               \
            }                                                                                                              \
                                                                                                                           \
            Zstr start = StrIterDataAt(&si, StrIterIndex(&saved));                                                         \
            size pos   = StrIterIndex(&si) - StrIterIndex(&saved);                                                         \
            Str  temp  = StrInitFromCstr(start, pos, &scratch);                                                            \
    #undef _I_BOUND
    
    Zstr _read_Zstr(Zstr i, FmtInfo *fmt_info, Zstr *out) {
        (void)fmt_info;
        (void)out;
        (void)fmt_info;
        (void)out;
        LOG_FATAL("Zstr reads require explicit allocator provenance; use ZstrIO(zstr, alloc) instead");
        return i;
    }
    }
    
    Zstr _read_ZstrAlloc(Zstr i, FmtInfo *fmt_info, ZstrIOArg *arg) {
        char     **out           = NULL;
        char      *previous      = NULL;
        char      *previous      = NULL;
        char      *result        = NULL;
        Zstr       next          = NULL;
        Allocator *allocator_ptr = NULL;
        Str        temp;
    
            (void)IntToBytesBE(value, buffer, byte_len);
            if (!write_char_internal(o, fmt_info->flags, (Zstr)buffer, byte_len)) {
                AllocatorFree(StrAllocator(o), buffer);
                return false;
    
    #if FEATURE_BITVEC
    Zstr _read_BitVec(Zstr i, FmtInfo *fmt_info, BitVec *bv) {
        (void)fmt_info; // Unused parameter
        if (!i || !bv) {
        }
    
        Zstr start = StrIterDataAt(&si, StrIterIndex(&si));
    
        char c0 = 0;
    
    #if FEATURE_INT
    Zstr _read_Int(Zstr i, FmtInfo *fmt_info, Int *value) {
        if (!i || !value) {
            LOG_FATAL("Invalid arguments");
        StrIter saved        = si;
        StrIter digits_saved = si;
        Zstr    start        = StrIterDataAt(&si, StrIterIndex(&saved));
        u8      radix        = int_fmt_radix_from_flags(fmt_info);
    
    #if FEATURE_FLOAT
    Zstr _read_Float(Zstr i, FmtInfo *fmt_info, Float *value) {
        size  token_len = 0;
        Zstr  start     = NULL;
    Zstr _read_Float(Zstr i, FmtInfo *fmt_info, Float *value) {
        size  token_len = 0;
        Zstr  start     = NULL;
        Str   temp;
        Float parsed;
    #endif // FEATURE_FLOAT
    
    Zstr _read_f32(Zstr i, FmtInfo *fmt_info, f32 *v) {
        DefaultAllocator scratch = DefaultAllocatorInit();
        if (fmt_info && (fmt_info->flags & FMT_FLAG_CHAR)) {
            u32  temp = 0;
            Zstr next = read_chars_internal(i, (u8 *)&temp, sizeof(temp), fmt_info);
            *v        = (f32)temp;
            DefaultAllocatorDeinit(&scratch);
        if ((c == 'i' || c == 'I' || c == 'n' || c == 'N') || (c == '-' && (c1 == 'i' || c1 == 'I'))) {
            StrIter saved = si;
            Zstr    start = StrIterDataAt(&si, StrIterIndex(&si));
            while (StrIterPeek(&si, &c) && !IS_SPACE(c)) {
                StrIterMustNext(&si);
        }
    
        Zstr start = StrIterDataAt(&si, StrIterIndex(&saved));
        size pos   = StrIterIndex(&si) - StrIterIndex(&saved);
    }
    
    static Zstr _read_r8(Zstr i, FmtInfo *fmt_info, u8 *v) {
        if (!i || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
    }
    
    static Zstr _read_r16(Zstr i, FmtInfo *fmt_info, u16 *v) {
        if (!i || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
    }
    
    static Zstr _read_r32(Zstr i, FmtInfo *fmt_info, u32 *v) {
        if (!i || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
    }
    
    static Zstr _read_r64(Zstr i, FmtInfo *fmt_info, u64 *v) {
        if (!i || !fmt_info || !v) {
            LOG_FATAL("Invalid arguments");
    #include <Misra/Std/Log.h>
    #include <Misra/Std/Memory.h>
    #include <Misra/Std/Zstr.h>
    
    size ZstrLen(Zstr str) {
    #include <Misra/Std/Zstr.h>
    
    size ZstrLen(Zstr str) {
        if (!str) {
            LOG_FATAL("Invalid arguments");
        }
    
        Zstr s = str;
        while (*s)
            s++;
    }
    
    i32 ZstrCompare(Zstr s1, Zstr s2) {
        if (!s1 || !s2) {
            LOG_FATAL("Invalid arguments");
    // is the generic-callback shape (sizeof the Zstr slot, = sizeof(Zstr));
    // the real length is walked here until the NUL.
    u64 zstr_hash(const Zstr *key, u32 ignored_size) {
        Zstr      s    = NULL;
        const u8 *ptr  = NULL;
    // the real length is walked here until the NUL.
    u64 zstr_hash(const Zstr *key, u32 ignored_size) {
        Zstr      s    = NULL;
        const u8 *ptr  = NULL;
        u64       hash = 1469598103934665603ULL;
    }
    
    i32 zstr_compare(const Zstr *a, const Zstr *b, u32 ignored_size) {
        i32 cmp = 0;
    }
    
    i32 ZstrCompareN(Zstr s1, Zstr s2, size n) {
        if (!s1 || !s2) {
            LOG_FATAL("Invalid arguments");
    }
    
    i32 ZstrCompareIgnoreCase(Zstr s1, Zstr s2) {
        if (!s1 || !s2) {
            LOG_FATAL("Invalid arguments");
    }
    
    i32 ZstrCompareNIgnoreCase(Zstr s1, Zstr s2, size n) {
        if (!s1 || !s2) {
            LOG_FATAL("Invalid arguments");
    }
    
    Zstr ZstrFindChar(Zstr str, char ch) {
        if (!str) {
            LOG_FATAL("Invalid arguments");
    }
    
    Zstr zstr_dup_n(Zstr src, size n, Allocator *alloc) {
        if (!src || !alloc) {
            LOG_FATAL("Invalid arguments");
    }
    
    Zstr zstr_dup(Zstr src, Allocator *alloc) {
        if (!src) {
            LOG_FATAL("Invalid arguments");
    
    bool zstr_init_clone(void *dst_ptr, const void *src_ptr, const Allocator *alloc) {
        Zstr       *dst = (Zstr *)dst_ptr;
        const Zstr *src = (const Zstr *)src_ptr;
    bool zstr_init_clone(void *dst_ptr, const void *src_ptr, const Allocator *alloc) {
        Zstr       *dst = (Zstr *)dst_ptr;
        const Zstr *src = (const Zstr *)src_ptr;
    
        if (!dst || !src || !*src || !alloc) {
    
    void zstr_deinit(void *zs_ptr, const Allocator *alloc) {
        Zstr *zs = (Zstr *)zs_ptr;
    
        if (!zs || !alloc) {
    }
    
    i64 ZstrToI64(Zstr s, Zstr *endptr) {
        if (!s) {
            if (endptr)
        // Overflow saturates so callers see a pinned value rather than a
        // silent wrap.
        Zstr      digit_start = s;
        const u64 bound       = neg ? ((u64)1 << 63) : (u64)0x7FFFFFFFFFFFFFFFULL;
        u64       val         = 0;
    }
    
    f64 ZstrToF64(Zstr s, Zstr *endptr) {
        if (!s) {
            if (endptr)
            s++;
        }
        Zstr digit_start = s;
        f64  val         = 0.0;
        while (*s >= '0' && *s <= '9') {
    }
    
    Zstr ZstrFindSubstring(Zstr haystack, Zstr needle) {
        if (!needle) {
            LOG_FATAL("Invalid arguments");
    }
    
    Zstr ZstrFindSubstringN(Zstr haystack, Zstr needle, size needle_len) {
        if (!haystack || !needle) {
            LOG_FATAL("Invalid arguments");
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Str/Private.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Vec/Private.h>
    #include <Misra/Std/Log.h>
    }
    
    bool str_try_init_from_cstr(Str *out, Zstr cstr, size len, Allocator *alloc) {
        if (!out || !cstr) {
            LOG_FATAL("Invalid arguments");
    }
    
    Str str_init_from_cstr(Zstr cstr, size len, Allocator *alloc) {
        Str result = StrInit(alloc);
    }
    
    i32 str_cmp_zstr(const Str *s, Zstr other) {
        ValidateStr(s);
        return ZstrCompare(StrBegin(s), other);
    }
    
    i32 str_cmp_cstr(const Str *s, Zstr other, size other_len) {
        ValidateStr(s);
        return ZstrCompareN(StrBegin(s), other, other_len);
    }
    
    i32 str_cmp_zstr_ignore_case(const Str *s, Zstr other) {
        ValidateStr(s);
        return ZstrCompareIgnoreCase(StrBegin(s), other);
    }
    
    i32 str_cmp_cstr_ignore_case(const Str *s, Zstr other, size other_len) {
        ValidateStr(s);
        return ZstrCompareNIgnoreCase(StrBegin(s), other, other_len);
    }
    
    Zstr str_find_cstr(const Str *s, Zstr key, size key_len) {
        ValidateStr(s);
        return ZstrFindSubstringN(StrBegin(s), key, key_len);
    }
    
    Zstr str_find_zstr(const Str *s, Zstr key) {
        ValidateStr(s);
        return ZstrFindSubstring(StrBegin(s), key);
    }
    
    Zstr str_find_str(const Str *s, const Str *key) {
        ValidateStr(s);
        ValidateStr(key);
    }
    
    static StrIters str_split_to_iters_impl(Str *s, Zstr key, size keylen) {
        ValidateStr(s);
    
        StrIters sv   = (StrIters)VecInit(s->allocator);
        Zstr     prev = s->data;
        Zstr     end  = s->data + s->length;
        StrIters sv   = (StrIters)VecInit(s->allocator);
        Zstr     prev = s->data;
        Zstr     end  = s->data + s->length;
    
        while (prev <= end) {
    
        while (prev <= end) {
            Zstr next = ZstrFindSubstringN(prev, key, keylen);
            if (next) {
                StrIter si = {.data = (char *)prev, .length = next - prev, .pos = 0, .alignment = 1};
    }
    
    StrIters str_split_to_iters_zstr(Str *s, Zstr key) {
        return str_split_to_iters_impl(s, key, ZstrLen(key));
    }
    }
    
    static Strs str_split_impl(Str *s, Zstr key, size keylen) {
        ValidateStr(s);
        Strs sv        = (Strs)VecInit(s->allocator);
        sv.copy_deinit = (GenericCopyDeinit)str_deinit;
        Zstr prev      = s->data;
    
        if (prev) {
    
        if (prev) {
            Zstr end = s->data + s->length;
            while (prev <= end) {
                Zstr next = ZstrFindSubstringN(prev, key, keylen);
            Zstr end = s->data + s->length;
            while (prev <= end) {
                Zstr next = ZstrFindSubstringN(prev, key, keylen);
                if (next) {
                    Str tmp = StrInitFromCstr(prev, next - prev, s->allocator);
    }
    
    Strs str_split_zstr(Str *s, Zstr key) {
        return str_split_impl(s, key, ZstrLen(key));
    }
    }
    
    size str_index_of_cstr(const Str *s, Zstr key, size key_len) {
        Zstr found = NULL;
    
    size str_index_of_cstr(const Str *s, Zstr key, size key_len) {
        Zstr found = NULL;
    
        ValidateStr(s);
    }
    
    size str_index_of_zstr(const Str *s, Zstr key) {
        if (!key) {
            LOG_FATAL("Invalid arguments");
    }
    
    bool str_contains_cstr(const Str *s, Zstr key, size key_len) {
        return str_index_of_cstr(s, key, key_len) != SIZE_MAX;
    }
    }
    
    bool str_contains_zstr(const Str *s, Zstr key) {
        return str_index_of_zstr(s, key) != SIZE_MAX;
    }
    }
    
    static inline bool is_strip_char(char c, Zstr strip_chars) {
        Zstr p = strip_chars;
        while (*p) {
    
    static inline bool is_strip_char(char c, Zstr strip_chars) {
        Zstr p = strip_chars;
        while (*p) {
            if (c == *p)
    //                 = -1 means from left
    //                 = 1 means from right
    Str strip_str(Str *s, Zstr chars_to_strip, int split_direction) {
        ValidateStr(s);
        }
    
        Zstr strip_chars = chars_to_strip ? chars_to_strip : " \t\n\r\v\f";
        Zstr start       = s->data;
        Zstr end         = s->data + s->length - 1;
    
        Zstr strip_chars = chars_to_strip ? chars_to_strip : " \t\n\r\v\f";
        Zstr start       = s->data;
        Zstr end         = s->data + s->length - 1;
        Zstr strip_chars = chars_to_strip ? chars_to_strip : " \t\n\r\v\f";
        Zstr start       = s->data;
        Zstr end         = s->data + s->length - 1;
    
        if (split_direction <= 0) {
    }
    
    static inline bool starts_with(Zstr data, size data_len, Zstr prefix, size prefix_len) {
        return data_len >= prefix_len && MemCompare(data, prefix, prefix_len) == 0;
    }
    }
    
    static inline bool ends_with(Zstr data, size data_len, Zstr suffix, size suffix_len) {
        return data_len >= suffix_len && MemCompare(data + data_len - suffix_len, suffix, suffix_len) == 0;
    }
    }
    
    bool str_starts_with_zstr(const Str *s, Zstr prefix) {
        ValidateStr(s);
        return starts_with(s->data, s->length, prefix, ZstrLen(prefix));
    }
    
    bool str_ends_with_zstr(const Str *s, Zstr suffix) {
        ValidateStr(s);
        return ends_with(s->data, s->length, suffix, ZstrLen(suffix));
    }
    
    bool str_starts_with_cstr(const Str *s, Zstr prefix, size prefix_len) {
        ValidateStr(s);
        return starts_with(s->data, s->length, prefix, prefix_len);
    }
    
    bool str_ends_with_cstr(const Str *s, Zstr suffix, size suffix_len) {
        ValidateStr(s);
        return ends_with(s->data, s->length, suffix, suffix_len);
    }
    
    void str_replace_cstr(Str *s, Zstr match, size match_len, Zstr replacement, size replacement_len, size count) {
        ValidateStr(s);
        size i        = 0;
    }
    
    void str_replace_zstr(Str *s, Zstr match, Zstr replacement, size count) {
        ValidateStr(s);
        str_replace_cstr(s, match, ZstrLen(match), replacement, ZstrLen(replacement), count);
    
        if (isnan_f64(value)) {
            Zstr nan_str = config->uppercase ? "NAN" : "nan";
            for (size i = 0; i < 3; i++) {
                if (!StrPushBackR(str, nan_str[i])) {
                }
            }
            Zstr inf_str = config->uppercase ? "INF" : "inf";
            for (size i = 0; i < 3; i++) {
                if (!StrPushBackR(str, inf_str[i])) {
    }
    
    static size map_validate_policy_index(size idx, size capacity, Zstr callback_name) {
        if (capacity && idx >= capacity) {
            LOG_FATAL("{} returned index {} for capacity {}", callback_name, idx, capacity);
    
    #include <Misra/Std/Container/Int.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Int/Private.h>
    #include <Misra/Std/Container/BitVec.h>
    static inline void int_store_le8(u8 *data, u64 byte_len, u64 off, u64 value);
    static bool        int_validate_radix(u8 radix);
    static bool int_try_from_str_radix_impl(Int *out, Zstr digits, u64 length, u64 start, u8 radix, bool allow_underscores);
    static bool int_try_from_i64_with_allocator(Int *out, i64 value, Allocator *alloc);
    static bool int_try_clone_value(Int *out, const Int *value);
    
    static bool
        int_try_from_str_radix_impl(Int *out, Zstr digits, u64 length, u64 start, u8 radix, bool allow_underscores) {
        Int  result;
        bool saw_digit = false;
    }
    
    bool int_try_from_str_zstr(Int *out, Zstr decimal) {
        u64 start = 0;
        u64 len   = 0;
    }
    
    Int int_from_str_zstr(Zstr decimal, Allocator *alloc) {
        Int out = IntInit(alloc);
    }
    
    bool int_try_from_str_radix_zstr(Int *out, Zstr digits, u8 radix) {
        u64 start = 0;
        u64 len   = 0;
    }
    
    Int int_from_str_radix_zstr(Zstr digits, u8 radix, Allocator *alloc) {
        Int out = IntInit(alloc);
    }
    
    bool int_try_from_binary_zstr(Int *out, Zstr binary) {
        u64 start = 0;
        u64 len   = 0;
    }
    
    Int int_from_binary_zstr(Zstr binary, Allocator *alloc) {
        Int out = IntInit(alloc);
    }
    
    bool int_try_from_oct_str_zstr(Int *out, Zstr octal) {
        u64 start = 0;
        u64 len   = 0;
    }
    
    Int int_from_oct_str_zstr(Zstr octal, Allocator *alloc) {
        Int out = IntInit(alloc);
    }
    
    bool int_try_from_hex_str_zstr(Int *out, Zstr hex) {
        u64 len = 0;
    }
    
    Int int_from_hex_str_zstr(Zstr hex, Allocator *alloc) {
        Int out = IntInit(alloc);
    
    #include <Misra/Std/Container/Float.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Float/Private.h>
    #include <Misra/Std/Container/Int.h>
    }
    
    static bool float_try_from_str_impl(Float *out, Zstr text, size length) {
        Float result;
        Str   digits;
    
            if (ch == 'e' || ch == 'E') {
                Zstr      endptr     = NULL;
                Zstr      exp_start  = NULL;
                long long parsed     = 0;
            if (ch == 'e' || ch == 'E') {
                Zstr      endptr     = NULL;
                Zstr      exp_start  = NULL;
                long long parsed     = 0;
                size      exp_offset = 0;
    }
    
    bool float_try_from_str_zstr(Float *out, Zstr text) {
        if (!out || !text) {
            LOG_FATAL("Invalid arguments");
    }
    
    Float float_from_str_zstr(Zstr text, Allocator *alloc) {
        Float result = FloatInit(alloc);
    
    #include <Misra/Std/Container/BitVec.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Memory.h>
    }
    
    static bool bitvec_try_from_str_impl(BitVec *out, Zstr str, u64 str_len, Allocator *alloc) {
        if (!str) {
            LOG_FATAL("str is NULL");
    }
    
    bool bitvec_try_from_str_zstr(BitVec *out, Zstr str, Allocator *alloc) {
        if (!str) {
            LOG_FATAL("str is NULL");
    }
    
    BitVec bitvec_from_str_zstr(Zstr str, Allocator *alloc) {
        BitVec result;
    }
    
    bool bitvec_regex_match_zstr(BitVec *bv, Zstr pattern) {
        ValidateBitVec(bv);
        if (!pattern) {
    }
    
    static void debug_emit_trace(const StackFrame *frames, size count, Zstr label, Allocator *meta) {
        if (!count) {
            LOG_ERROR("    {} trace: (none captured)", label);
    #include "../_Syscall.h"
    
    Zstr DirEntryTypeToZstr(DirEntryType type) {
        switch (type) {
            case DIR_ENTRY_TYPE_UNKNOWN :
    #if PLATFORM_WINDOWS
    // Windows-specific implementation using FindFirstFile/FindNextFile
    DirContents dir_get_contents(Zstr path, Allocator *alloc) {
        if (!path || !alloc) {
            LOG_FATAL("Invalid argument");
    }
    
    DirContents dir_get_contents(Zstr path, Allocator *alloc) {
        if (!path || !alloc) {
            LOG_FATAL("Invalid arguments");
            for (long off = 0; off < n;) {
                struct kernel_dirent *de = (struct kernel_dirent *)(void *)(buf + off);
                Zstr                  nm = de->d_name;
    #    if PLATFORM_DARWIN
                // Darwin gives d_namlen explicitly (not null-terminated
    
    // Cross-platform function to get file size
    i64 file_get_size(Zstr filename) {
    #if PLATFORM_WINDOWS
        // Windows-specific code using GetFileSizeEx
    // ---------------------------------------------------------------------------
    
    i8 file_remove(Zstr path) {
        if (!path) {
            LOG_FATAL("FileRemove: NULL path");
    }
    
    i8 dir_remove(Zstr path) {
        if (!path) {
            LOG_FATAL("DirRemove: NULL path");
    #define DIR_CREATE_MODE 0755
    
    i8 dir_create(Zstr path) {
        if (!path) {
            LOG_FATAL("DirCreate: NULL path");
    // DirCreateAll to make EEXIST tolerant (idempotent). Avoids re-walking
    // the existing tree on the second invocation.
    static bool dir_already_exists(Zstr path) {
    #if PLATFORM_WINDOWS
        DWORD attrs = GetFileAttributesA(path);
    }
    
    i8 dir_create_all(Zstr path) {
        if (!path) {
            LOG_FATAL("DirCreateAll: NULL path");
                    data[i]    = 0;
                    if (!dir_already_exists(data)) {
                        if (!DirCreate((Zstr)data)) {
                            // DirCreate logged the syscall error; re-check
                            // in case a concurrent process beat us to it.
    #define DIR_REMOVE_ALL_PATH_CAP 512
    
    i8 dir_remove_all(Zstr path) {
        if (!path) {
            LOG_FATAL("DirRemoveAll: NULL path");
        for (size i = 0; i < VecLen(&dc); ++i) {
            DirEntry *e        = VecPtrAt(&dc, i);
            Zstr      entry_nm = StrBegin(&e->name);
            if (ZstrCompare(entry_nm, ".") == 0 || ZstrCompare(entry_nm, "..") == 0) {
                continue;
    //
    // Returns true on success; `out` is populated with an opened Elf.
    static bool try_open_sidecar(Zstr main_path, const Elf *main, Elf *out, Allocator *alloc) {
        Str path = StrInit(alloc);
        // (2-4) debuglink in standard locations
        if (main->debuglink_name && main->debuglink_name[0]) {
            Zstr cand_prefix = "/usr/lib/debug";
    
            // (2) {dir}/{name}
    // ---------------------------------------------------------------------------
    
    static ResolverCacheEntry *resolver_cache_find_or_open(SymbolResolver *self, Zstr path) {
        for (u64 i = 0; i < VecLen(&self->cache); ++i) {
            ResolverCacheEntry *e = VecPtrAt(&self->cache, i);
    //
    // On success populates `out_path` (an owned Str the caller frees).
    static bool find_pdb(const Pe *pe, Zstr pe_path, Str *out_path) {
        const PeCodeViewInfo *cv = PeCodeView(pe);
        if (!cv->present || !cv->pdb_path)
    
        // (2) basename alongside PE
        Zstr pdb_base = sys_basename_of(cv->pdb_path);
        if (pdb_base[0] == '\0')
            return false;
    
    // Find an existing entry for `module_path` or create a fresh one.
    static PdbCacheEntry *cache_find_or_open(PdbCache *self, Zstr module_path) {
        for (size i = 0; i < VecLen(&self->entries); ++i) {
            PdbCacheEntry *e = VecPtrAt(&self->entries, i);
    bool pdb_cache_resolve_zstr(
        PdbCache *self,
        Zstr      module_path,
        u64       module_base,
        u64       runtime_ip,
        u64       module_base,
        u64       runtime_ip,
        Zstr     *out_name,
        u32      *out_offset
    ) {
        u64        module_base,
        u64        runtime_ip,
        Zstr      *out_name,
        u32       *out_offset
    ) {
    
    #include <Misra/Sys/Dns.h>
    #include <Misra/Std/Zstr.h>
    
    #include <Misra/Parsers/Dns.h>
    // on the Str. Returns false on read error; missing file returns true
    // with an empty Str.
    static bool slurp_file(Zstr path, Str *out) {
        File f = FileOpen(path, "rb");
        if (!FileIsOpen(&f)) {
    }
    
    static void parse_hosts_path(HostsTable *table, Zstr path, Allocator *alloc) {
        Str buf = StrInit(alloc);
        if (!slurp_file(path, &buf)) {
                // the longest reasonable IPv6-with-zone-id literal.
                StrInitStack(ip_buf, 64) {
                    StrPushBackMany(&ip_buf, (Zstr)StrIterDataAt(&si, ip_start), ip_len);
                    got_v4 = parse_ipv4(StrBegin(&ip_buf), v4);
                    if (!got_v4) {
    
                HostsEntry e = {0};
                e.name       = StrInitFromCstr((Zstr)StrIterDataAt(&si, nm_start), nm_len, alloc);
                ascii_lower((u8 *)StrBegin(&e.name), StrLen(&e.name));
                if (got_v4) {
    // ---------------------------------------------------------------------------
    
    static void parse_resolv_path(DnsAddrs *out, Zstr path, Allocator *alloc) {
        Str buf = StrInit(alloc);
        if (!slurp_file(path, &buf)) {
                if (ip_len > 0 && ip_len < 64) {
                    StrInitStack(ip_buf, 64) {
                        StrPushBackMany(&ip_buf, (Zstr)StrIterDataAt(&si, ip_start), ip_len);
                        u8 v4[4]  = {0};
                        u8 v6[16] = {0};
    // ---------------------------------------------------------------------------
    
    static bool dns_add_path(DnsResolver *self, Zstr path, bool do_hosts, bool do_resolv) {
        if (!self || !path)
            return false;
    }
    
    static bool dns_add_path_len(DnsResolver *self, Zstr path, u64 len, bool do_hosts, bool do_resolv) {
        if (!self || !path)
            return false;
    }
    
    bool dns_resolver_add_path_zstr(DnsResolver *self, Zstr path, u64 len) {
        return dns_add_path_len(self, path, len, true, true);
    }
    }
    
    bool dns_resolver_add_hosts_path_zstr(DnsResolver *self, Zstr path, u64 len) {
        return dns_add_path_len(self, path, len, true, false);
    }
    }
    
    bool dns_resolver_add_resolv_path_zstr(DnsResolver *self, Zstr path, u64 len) {
        return dns_add_path_len(self, path, len, false, true);
    }
    
    // Strip trailing dot, lowercase, write into `out` (caller-managed Str).
    static void normalize_hostname(Zstr name, Str *out) {
        if (!name) {
            return;
    // response's id is checked to match before the records are extracted.
    static bool
        try_one_query(DnsResolver *self, const SocketAddr *ns, Zstr hostname, DnsType qtype, u16 port, DnsAddrs *out) {
        // Per-call scratch: one DNS query buffer (<= 1232 B) plus the parsed
        // response with its records vector. Everything is dropped at function
    }
    
    bool dns_resolve_5_zstr(DnsResolver *self, Zstr hostname, u16 port, SocketKind kind, DnsAddrs *out) {
        (void)kind; // protocol byte doesn't affect resolution
        if (!self || !hostname || !out) {
            // is a valid Zstr for the matchers / DNS query below.
            normalize_hostname(hostname, &norm);
            Zstr nq = StrBegin(&norm);
    
            // 1. /etc/hosts fast path.
    }
    
    bool dns_resolve_4_vec_zstr(DnsResolver *self, Zstr spec, SocketKind kind, DnsAddrs *out) {
        if (!self || !spec || !out) {
            return false;
    }
    
    bool dns_resolve_4_one_zstr(DnsResolver *self, Zstr spec, SocketKind kind, SocketAddr *out) {
        if (!self || !spec || !out) {
            return false;
            DWORD64     ip       = (DWORD64)(u64)frames[i].ip;
            bool        named    = false;
            Zstr sym_name = NULL;
            u32         sym_off  = 0;
                DWORD64 d_off = 0;
                if (SymFromAddr(proc, ip, &d_off, sym)) {
                    sym_name = (Zstr)sym->Name;
                    sym_off  = (u32)d_off;
                    named    = true;
            DWORD line_disp = 0;
            if (g_dbghelp_initialized && SymGetLineFromAddr64(proc, ip, &line_disp, &line) && line.FileName) {
                Zstr fname = sys_basename_of(line.FileName);
                StrAppendFmt(out, " ({}:{})", fname, (u32)line.LineNumber);
            }
    extern u32         _dyld_image_count(void);
    extern const void *_dyld_get_image_header(u32 image_index);
    extern Zstr _dyld_get_image_name(u32 image_index);
    extern i64         _dyld_get_image_vmaddr_slide(u32 image_index);
    
    #    if FEATURE_PARSER_MACHO
    static bool dyld_image_for_ip(void *ip, Zstr *out_path, u64 *out_slide) {
        u64 ipx = (u64)ip;
        u32 n   = _dyld_image_count();
        for (size i = 0; i < count; ++i) {
            u64         ip       = (u64)frames[i].ip;
            Zstr sym_name = NULL;
            u32         sym_off  = 0;
            Zstr mod_path = NULL;
            Zstr sym_name = NULL;
            u32         sym_off  = 0;
            Zstr mod_path = NULL;
            bool        named    = false;
    
            if (named) {
                Zstr mod = sys_basename_of(mod_path);
                StrAppendFmt(out, "  #{} {}!{}+{x} [{x}]\n", (u32)i, mod, sym_name, (u64)sym_off, ip);
            } else if (mod_path) {
                StrAppendFmt(out, "  #{} {}!{}+{x} [{x}]\n", (u32)i, mod, sym_name, (u64)sym_off, ip);
            } else if (mod_path) {
                Zstr mod = sys_basename_of(mod_path);
                StrAppendFmt(out, "  #{} {}+? [{x}]\n", (u32)i, mod, ip);
            } else {
    static void emit_resolved_line(Str *out, u32 idx, const ResolvedSymbol *r, void *ip) {
        if (r->symbol_name) {
            Zstr mod = sys_basename_of(r->module_path);
            StrAppendFmt(out, "  #{} {}!{}+{x} [{x}]", idx, mod, r->symbol_name, r->offset, (u64)ip);
        } else if (r->module_path) {
            StrAppendFmt(out, "  #{} {}!{}+{x} [{x}]", idx, mod, r->symbol_name, r->offset, (u64)ip);
        } else if (r->module_path) {
            Zstr mod = sys_basename_of(r->module_path);
            StrAppendFmt(out, "  #{} {}+{x} [{x}]", idx, mod, r->offset, (u64)ip);
        } else {
        }
        if (r->source_file) {
            Zstr file = sys_basename_of(r->source_file);
            if (r->source_line > 0) {
                StrAppendFmt(out, " ({}:{})", file, r->source_line);
    // Parse a decimal port number (0..65535) from a NUL-terminated string.
    // Empty / non-numeric input -> false. Out-of-range -> false.
    static bool parse_port(Zstr s, u16 *out) {
        if (!s || !*s)
            return false;
            return false;
        u32 v = 0;
        for (Zstr p = s; *p; ++p) {
            if (*p < '0' || *p > '9')
                return false;
    }
    
    static bool split_host_port(Zstr spec, char *host_out, size host_cap, Zstr *port_out) {
        if (!spec || !host_out || !port_out) {
            return false;
    
        if (spec[0] == '[') {
            Zstr close = NULL;
            for (Zstr p = spec + 1; *p; ++p) {
                if (*p == ']') {
        if (spec[0] == '[') {
            Zstr close = NULL;
            for (Zstr p = spec + 1; *p; ++p) {
                if (*p == ']') {
                    close = p;
        }
    
        Zstr colon = NULL;
        for (Zstr p = spec; *p; ++p) {
            if (*p == ':') {
    
        Zstr colon = NULL;
        for (Zstr p = spec; *p; ++p) {
            if (*p == ':') {
                colon = p;
    // ---------------------------------------------------------------------------
    
    bool socket_addr_parse_zstr(SocketAddr *out, Zstr spec, SocketKind kind) {
        if (!out) {
            LOG_FATAL("SocketAddrParse: out is NULL");
        StrInitStack(host, 256) {
            char *host_data = StrBegin(&host);
            Zstr  port_str  = NULL;
            if (!split_host_port(spec, host_data, 256, &port_str)) {
                break;
                StrResize(&host, ZstrLen(host_data));
                port = FROM_BIG_ENDIAN2(sa->sin_port);
                StrAppendFmt(&out, "{}:{}", (Zstr)host_data, (u32)port);
            } else if (addr->family == SOCKET_FAMILY_INET6) {
                const struct sockaddr_in6 *sa = (const struct sockaddr_in6 *)addr->raw;
                StrResize(&host, ZstrLen(host_data));
                port = FROM_BIG_ENDIAN2(sa->sin6_port);
                StrAppendFmt(&out, "[{}]:{}", (Zstr)host_data, (u32)port);
            } else {
                LOG_ERROR("SocketAddrFormat: unknown family {}", (u32)addr->family);
        int len = (int)((n > (size)0x7FFFFFFF) ? (size)0x7FFFFFFF : n);
        // No MSG_NOSIGNAL needed -- Winsock doesn't raise SIGPIPE.
        int r = send((SOCKET)s, (Zstr)buf, len, 0);
        if (r == SOCKET_ERROR) {
            LOG_SOCK_ERROR(0, "send() failed");
    
    static bool plat_setsockopt(SockFd s, int level, int optname, const void *optval, u32 optlen) {
        if (setsockopt((SOCKET)s, level, optname, (Zstr)optval, (int)optlen) == SOCKET_ERROR) {
            LOG_SOCK_ERROR(0, "setsockopt() failed");
            return false;
    // Compose the conventional dSYM location for `binary_path`:
    //   <binary_path>.dSYM/Contents/Resources/DWARF/<basename>
    static bool compose_dsym_path(Zstr binary_path, Str *out) {
        if (!binary_path)
            return false;
        if (!binary_path)
            return false;
        Zstr base = sys_basename_of(binary_path);
        if (base[0] == '\0')
            return false;
    // ---------------------------------------------------------------------------
    
    static MachoCacheEntry *cache_find_or_create(MachoCache *self, Zstr module_path) {
        for (size i = 0; i < VecLen(&self->entries); ++i) {
            MachoCacheEntry *e = VecPtrAt(&self->entries, i);
    bool macho_cache_resolve_zstr(
        MachoCache *self,
        Zstr        module_path,
        u64         slide,
        u64         runtime_ip,
        u64         slide,
        u64         runtime_ip,
        Zstr       *out_name,
        u32        *out_offset
    ) {
        u64         slide,
        u64         runtime_ip,
        Zstr       *out_name,
        u32        *out_offset
    ) {
    #define MISRA_SYS_IP_PARSE_H
    
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
    /// Parse "a.b.c.d" into four octets. Empty / NULL / out-of-range / any
    /// trailing bytes -> false.
    static inline bool parse_ipv4(Zstr s, u8 octets[4]) {
        if (!s)
            return false;
    /// RFC 5952 "::" compression. Does not handle zone IDs or embedded
    /// IPv4-in-IPv6.
    static inline bool parse_ipv6(Zstr s, u8 bytes[16]) {
        if (!s)
            return false;
    #include <Misra/Std/Log.h>
    #include <Misra/Std/Memory.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Sys.h>
    #include "../_Syscall.h"
    #    endif
    }
    static inline long proc_readlink(Zstr path, char *buf, unsigned long sz) {
    #    if PLATFORM_DARWIN || ARCHITECTURE_X86_64
        return direct_sys3(MISRA_SYS_readlink, (long)(u64)path, (long)(u64)buf, (long)sz);
    #define WRITE_END 1
    
    Proc proc_init(Zstr filepath, char **argv, char **envp, Allocator *alloc) {
        Proc proc = {0};
    #if PLATFORM_UNIX
    // Sys/Backtrace already makes per-frame.
    #    if PLATFORM_DARWIN
        extern Zstr _dyld_get_image_name(u32 image_index);
        Zstr        exe = _dyld_get_image_name(0);
        if (exe) {
    #    if PLATFORM_DARWIN
        extern Zstr _dyld_get_image_name(u32 image_index);
        Zstr        exe = _dyld_get_image_name(0);
        if (exe) {
            *exe_path = StrInitFromCstr(exe, ZstrLen(exe), alloc);
    #include <Misra/Std/File.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
    /// concurrent unlink, which is acceptable for the existence-probe
    /// callers (cache lookups, sidecar discovery).
    static inline bool sys_path_exists(Zstr path) {
        File f = FileOpen(path, "rb");
        if (!FileIsOpen(&f)) {
    /// '/' or '\\'). Returns "" on NULL; the returned pointer aliases
    /// `path` itself, so it stays valid for `path`'s lifetime.
    static inline Zstr sys_basename_of(Zstr path) {
        if (!path)
            return "";
        if (!path)
            return "";
        Zstr base = path;
        for (Zstr p = path; *p; ++p) {
            if (*p == '/' || *p == '\\')
            return "";
        Zstr base = path;
        for (Zstr p = path; *p; ++p) {
            if (*p == '/' || *p == '\\')
                base = p + 1;
    /// including the last separator) into `out`. No-op on NULL or on paths
    /// with no separator.
    static inline void sys_append_dirname(Str *out, Zstr path) {
        if (!path)
            return;
        if (!path)
            return;
        Zstr last_sep = NULL;
        for (Zstr p = path; *p; ++p) {
            if (*p == '/' || *p == '\\')
            return;
        Zstr last_sep = NULL;
        for (Zstr p = path; *p; ++p) {
            if (*p == '/' || *p == '\\')
                last_sep = p;
            if (!terminated)
                continue;
            cv->pdb_path = (Zstr)path_start;
            cv->present  = true;
            return; // first CodeView entry wins
    }
    
    bool pe_open(Pe *out, Zstr path, Allocator *alloc) {
        if (!out || !path || !alloc) {
            LOG_FATAL("PeOpen: NULL argument (contract violation)");
    }
    
    const PeSection *pe_find_section_zstr(const Pe *self, Zstr name) {
        if (!self || !name)
            return NULL;
            u64  u;
            i64  i;
            Zstr s;
            u64  off;
        };
            }
            case DW_FORM_string : {
                Zstr s = BufReadZstr(cur);
                if (!s)
                    return false;
            u64  low_pc = 0, high_pc = 0;
            bool high_pc_is_offset = false;
            Zstr name              = NULL;
            u64  name_str_off      = 0;
            bool name_from_strp    = false;
                    // Resolve name into the pool now (or later if it came
                    // from .debug_str — same pool either way).
                    Zstr src;
                    if (name_from_strp) {
                        src = (Zstr)(debug_str + name_str_off);
                    Zstr src;
                    if (name_from_strp) {
                        src = (Zstr)(debug_str + name_str_off);
                    } else {
                        src = name;
    // e.g. "example.com" -> 0x07 "example" 0x03 "com" 0x00.
    // Returns false on label > 63 bytes or total > 255 bytes.
    static bool encode_qname(DnsWireBuf *out, Zstr name) {
        if (!name) {
            return false;
    }
    
    bool dns_build_query_zstr(DnsWireBuf *out, u16 id, Zstr name, DnsType type) {
        if (!out || !name) {
            return false;
    #include <Misra/Std/Log.h>
    #include <Misra/Std/Memory.h>
    #include <Misra/Std/Zstr.h>
    
    
    static bool kvconfig_parse_i64_value(const Str *value, i64 *out) {
        Zstr endptr = NULL;
        i64  parsed;
    
    static bool kvconfig_parse_f64_value(const Str *value, f64 *out) {
        Zstr endptr = NULL;
        f64  parsed;
    }
    
    Str *kvconfig_get_ptr_zstr(KvConfig *cfg, Zstr key) {
        Str  lookup = {0};
        Str *value  = NULL;
    }
    
    Str kvconfig_get_zstr(KvConfig *cfg, Zstr key) {
        Str *value = kvconfig_get_ptr_zstr(cfg, key);
    }
    
    bool kvconfig_contains_zstr(KvConfig *cfg, Zstr key) {
        return kvconfig_get_ptr_zstr(cfg, key) != NULL;
    }
    }
    
    bool kvconfig_get_bool_zstr(KvConfig *cfg, Zstr key, bool *value) {
        Str *str = kvconfig_get_ptr_zstr(cfg, key);
    }
    
    bool kvconfig_get_i64_zstr(KvConfig *cfg, Zstr key, i64 *value) {
        Str *str = kvconfig_get_ptr_zstr(cfg, key);
    }
    
    bool kvconfig_get_f64_zstr(KvConfig *cfg, Zstr key, f64 *value) {
        Str *str = kvconfig_get_ptr_zstr(cfg, key);
    // invalidates earlier pointers -- we resolve to pointers in a second
    // pass after the walk completes.
    static bool pool_append_cstr(Str *pool, Zstr s, u64 *out_offset) {
        *out_offset = StrLen(pool);
        if (!StrPushBackMany(pool, s))
                    continue;
                }
                Zstr name = (Zstr)IterDataAt(&body, IterIndex(&body));
    
                (void)flags; // permissive: we don't filter by FUNCTION bit;
    }
    
    bool pdb_open(Pdb *out, Zstr path, Allocator *alloc) {
        if (!out || !path || !alloc) {
            LOG_FATAL("PdbOpen: NULL argument (contract violation)");
        out->perms       = perms;
        out->file_offset = offset;
        out->path        = (Zstr)StrIterDataAt(si, path_start_pos); // may be empty if anonymous
    
        if (line_terminator_pos < StrIterLength(si) && *StrIterDataAt(si, line_terminator_pos) == '\n') {
    
    #include <Misra/Parsers/Http.h>
    #include <Misra/Std/Zstr.h>
    
    #if FEATURE_FILE
    }
    
    HttpHeader *http_headers_find_zstr(HttpHeaders *headers, Zstr key) {
        if (!headers || !key) {
            LOG_FATAL("invalid arguments");
    }
    
    Zstr http_request_parse_zstr(HttpRequest *req, Zstr in) {
        if (!req || !req->allocator || !in) {
            LOG_FATAL("invalid arguments");
    
        Allocator *alloc   = req->allocator;
        Zstr       cursor  = in;
        Str        method  = StrInit(alloc);
        Str        version = StrInit(alloc);
    
        while (true) {
            Zstr line_start = cursor;
    
            if (0 == ZstrCompareN(cursor, "\r\n", 2)) {
    }
    
    Zstr http_request_parse_str(HttpRequest *req, const Str *in) {
        if (!req || !in) {
            LOG_FATAL("invalid arguments");
    // ---------------------------------------------------------------------------
    
    Zstr HttpResponseCodeToZstr(HttpResponseCode code) {
        switch (code) {
            case HTTP_RESPONSE_CODE_CONTINUE :
    }
    
    Zstr HttpContentTypeToZstr(HttpContentType type) {
        switch (type) {
            case HTTP_CONTENT_TYPE_TEXT_PLAIN :
        HttpResponseCode status,
        HttpContentType  content_type,
        Zstr             filepath
    ) {
        if (!response || !response->allocator || !filepath) {
            LOG_FATAL("invalid arguments");
        }
        return http_respond_with_file_zstr(response, status, content_type, (Zstr)StrBegin(filepath));
    }
    #endif
        }
    
        Zstr response_code = HttpResponseCodeToZstr(response->status_code);
        if (!response_code) {
            LOG_ERROR("HttpResponseSerialize: invalid/unknown response code {}", (u32)response->status_code);
            return out;
        }
        Zstr content_type = HttpContentTypeToZstr(response->content_type);
        if (!content_type) {
            LOG_ERROR("HttpResponseSerialize: invalid/unknown content type {}", (u32)response->content_type);
    #include <Misra/Parsers/JSON.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    
    static StrIter JSkipObject(StrIter si) {
    
        // convert to number
        Zstr end = NULL;
        if (is_flt) {
            num->f = ZstrToF64(StrBegin(&ns), &end);
        if (StrIterRemainingLength(&si) >= 4) {
            if (StrIterPeek(&si, &c) && c == 't') {
                Zstr pos = StrIterPos(&si);
                if (pos && ZstrCompareN(pos, "true", 4) == 0) {
                    StrIterMustMove(&si, 4);
            if (StrIterRemainingLength(&si) >= 5) {
                if (StrIterPeek(&si, &c) && c == 'f') {
                    Zstr pos = StrIterPos(&si);
                    if (pos && ZstrCompareN(pos, "false", 5) == 0) {
                        StrIterMustMove(&si, 5);
        if (StrIterRemainingLength(&si) >= 4) {
            if (StrIterPeek(&si, &c) && c == 'n') {
                Zstr pos = StrIterPos(&si);
                if (pos && ZstrCompareN(pos, "null", 4) == 0) {
                    StrIterMustMove(&si, 4);
        out->version = version;
    
        Zstr augmentation = BufReadZstr(body);
        if (!augmentation)
            return false;
                continue;
            MachoSymbol sym;
            sym.name          = (Zstr)(str_base + n_strx);
            sym.value         = n_value;
            sym.type          = n_type;
    }
    
    bool macho_open(Macho *out, Zstr path, Allocator *alloc) {
        if (!out || !path || !alloc) {
            LOG_FATAL("MachoOpen: NULL argument (contract violation)");
    }
    
    const MachoSection *macho_find_section(const Macho *self, Zstr segment, Zstr section) {
        if (!self || !segment || !section)
            return NULL;
    // ---------------------------------------------------------------------------
    
    static Zstr elf_str_at(const Elf *self, u64 strtab_offset, u64 strtab_size, u32 idx) {
        if ((u64)idx >= strtab_size) {
            return "";
        // read past the strtab. Scan forward; if no NUL is found inside
        // [idx, strtab_size), return an empty string.
        Zstr base = (Zstr)(BufData(&self->data) + strtab_offset);
        for (u64 p = idx; p < strtab_size; ++p) {
            if (base[p] == '\0') {
            return;
        }
        Zstr base = (Zstr)(BufData(&self->data) + dl->offset);
        // filename runs up to (and including) the NUL; CRC follows in the
        // last 4 bytes of the section, after alignment padding.
    }
    
    bool elf_open(Elf *out, Zstr path, Allocator *alloc) {
        if (!out || !path || !alloc) {
            LOG_FATAL("ElfOpen: NULL argument (contract violation)");
    }
    
    const ElfSection *elf_find_section_zstr(const Elf *self, Zstr name) {
        if (!self || !name)
            return NULL;
    // Append `s` (NUL-terminated) including its terminator into `pool` and
    // return the offset at which it was inserted.
    static bool pool_append(Str *pool, Zstr s, u64 *out_offset) {
        u64 start = StrLen(pool);
        if (!StrPushBackMany(pool, s))
        // include_directories
        while (IterIndex(&cur) < IterLength(&cur) && *IterDataAt(&cur, IterIndex(&cur)) != 0) {
            Zstr dir = BufReadZstr(&cur);
            if (!dir)
                return false;
        // file_names
        while (IterIndex(&cur) < IterLength(&cur) && *IterDataAt(&cur, IterIndex(&cur)) != 0) {
            Zstr name = BufReadZstr(&cur);
            if (!name)
                return false;
                u64 fo                           = VecAt(&pending_file_offsets, i);
                u64 dofs                         = VecAt(&pending_dir_offsets, i);
                VecPtrAt(&out->entries, i)->file = fo ? (Zstr)(StrBegin(&out->string_pool) + fo) : NULL;
                VecPtrAt(&out->entries, i)->dir  = dofs ? (Zstr)(StrBegin(&out->string_pool) + dofs) : NULL;
            }
                u64 dofs                         = VecAt(&pending_dir_offsets, i);
                VecPtrAt(&out->entries, i)->file = fo ? (Zstr)(StrBegin(&out->string_pool) + fo) : NULL;
                VecPtrAt(&out->entries, i)->dir  = dofs ? (Zstr)(StrBegin(&out->string_pool) + dofs) : NULL;
            }
        }
    int main(int argc, char **argv) {
        Scope(alloc, DefaultAllocator) {
            Zstr hostname = NULL;
    
            ArgParse ap = ArgParseInit("resolve", "look up a hostname via /etc/hosts and DNS");
                // bracket form on v6 to round-trip through SocketAddrParse.
                size n = StrLen(&s);
                Zstr p = StrBegin(&s);
                if (n >= 2 && p[n - 1] == '0' && p[n - 2] == ':') {
                    StrMustResize(&s, n - 2);
    }
    
    static void log_request_summary(Zstr client_addr, Zstr prefix_bytes, size prefix_len) {
        Scope(scope, DefaultAllocator) {
            Str raw = StrInit(scope);
    
            HttpRequest req = HttpRequestInit(scope);
            Zstr        end = HttpRequestParse(&req, (Zstr)StrBegin(&raw));
            if (end == StrBegin(&raw)) {
                LOG_INFO("[{}] (unparseable request, {} bytes)", client_addr, (u64)prefix_len);
                LOG_INFO("[{}] (unparseable request, {} bytes)", client_addr, (u64)prefix_len);
            } else {
                Zstr method = "?";
                switch (req.method) {
                    case HTTP_REQUEST_METHOD_GET :
    // directions close. `first_chunk` (if non-NULL) is sent toward `b`
    // before the poll loop runs, so the initial client read isn't lost.
    static void proxy_pump(Socket *a, Socket *b, Zstr first_chunk, size first_len) {
        if (first_chunk && first_len > 0) {
            if (SocketSend(b, first_chunk, first_len) < 0) {
    
        Scope(alloc, DefaultAllocator) {
            Zstr listen_spec   = NULL;
            Zstr upstream_spec = NULL;
        Scope(alloc, DefaultAllocator) {
            Zstr listen_spec   = NULL;
            Zstr upstream_spec = NULL;
    
            ArgParse ap = ArgParseInit("beam", "small reverse-proxy");
    #include <Misra/Std/Log.h>
    #include <Misra/Std/Memory.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Sys/Dir.h>
    // is the caller's Str; on success it holds the resolved name so the
    // caller can read it back and remove it.
    static bool write_test_file(Zstr text, Str *out_path, Allocator *alloc) {
        File f = FileOpenTemp(out_path, alloc);
        if (!FileIsOpen(&f)) {
        FileClose(&f);
    
        Zstr expected = "this is longer than the initial buffer";
        bool result   = (got == (i64)ZstrLen(expected)) && (StrLen(&body) == (size)ZstrLen(expected)) &&
                      ZstrCompare(StrBegin(&body), expected) == 0 && StrCapacity(&body) >= StrLen(&body) + 1;
        }
    
        Zstr msg   = "abcdefgh"; // 8 bytes
        i64  wrote = FileWrite(&f, msg, 8);
        bool ok    = (wrote == 8);
        FileClose(&seed);
    
        Zstr payload = "round-trip payload";
        u64  n       = ZstrLen(payload);
    
        Str  path;
        Zstr payload = "the quick brown fox jumps over the lazy dog"; // 43 bytes
        bool ok      = write_test_file(payload, &path, alloc_base);
        if (!ok) {
        FileClose(&seed);
    
        Zstr payload = "payload-through-the-convenience-API";
        u64  n       = ZstrLen(payload);
    
        BufIter it = BufIterFromBuf(&b);
        Zstr s1 = BufReadZstr(&it);
        Zstr s2 = BufReadZstr(&it);
        bool    ok = s1 && s2 && s1[0] == 'h' && s2[0] == 'w';
        BufIter it = BufIterFromBuf(&b);
        Zstr s1 = BufReadZstr(&it);
        Zstr s2 = BufReadZstr(&it);
        bool    ok = s1 && s2 && s1[0] == 'h' && s2[0] == 'w';
        ok         = ok && IterRemainingLength(&it) == 0;
    #include <Misra.h>
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra/Std/Zstr.h>
    
    #include "../Util/TestRunner.h"
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/ArgParse.h>
    #include <Misra/Std/Container/Str.h>
        ArgParse         p = ArgParseInit("prog", NULL, &a);
    
        Zstr listen = NULL;
        ArgRequired(&p, "-l", "--listen", &listen, "host:port");
        ArgParse         p = ArgParseInit("prog", NULL, &a);
    
        Zstr listen = NULL;
        ArgRequired(&p, "-l", "--listen", &listen, "host:port");
        ArgParse         p = ArgParseInit("prog", NULL, &a);
    
        Zstr listen = NULL;
        ArgRequired(&p, "-l", "--listen", &listen, "host:port");
        ArgParse         p = ArgParseInit("cp", NULL, &a);
    
        Zstr src = NULL;
        Zstr dst = NULL;
        ArgPositional(&p, "source", &src, "from");
    
        Zstr src = NULL;
        Zstr dst = NULL;
        ArgPositional(&p, "source", &src, "from");
        ArgPositional(&p, "dest", &dst, "to");
        ArgParse         p = ArgParseInit("cp", NULL, &a);
    
        Zstr src     = NULL;
        Zstr dst     = NULL;
        bool verbose = false;
    
        Zstr src     = NULL;
        Zstr dst     = NULL;
        bool verbose = false;
        ArgPositional(&p, "source", &src, "from");
        ArgParse         p = ArgParseInit("prog", NULL, &a);
    
        Zstr listen = NULL;
        ArgRequired(&p, "-l", "--listen", &listen, "");
        ArgParse         p = ArgParseInit("cp", NULL, &a);
    
        Zstr src = NULL;
        Zstr dst = NULL;
        ArgPositional(&p, "source", &src, "");
    
        Zstr src = NULL;
        Zstr dst = NULL;
        ArgPositional(&p, "source", &src, "");
        ArgPositional(&p, "dest", &dst, "");
        ArgParse         p = ArgParseInit("prog", NULL, &a);
    
        Zstr x = NULL;
        ArgPositional(&p, "x", &x, "");
    // ----------------------------------------------------------------------------
    
    static bool run_bool_value(Zstr text, bool *out) {
        DefaultAllocator a = DefaultAllocatorInit();
        ArgParse         p = ArgParseInit("prog", NULL, &a);
    
    static bool test_bool_value_truthy_spellings(void) {
        Zstr truthy[] = {"true", "1", "yes", "on"};
        for (u32 i = 0; i < 4; i++) {
            bool v = false;
    
    static bool test_bool_value_falsey_spellings(void) {
        Zstr falsey[] = {"false", "0", "no", "off"};
        for (u32 i = 0; i < 4; i++) {
            bool v = true;
        DefaultAllocator a      = DefaultAllocatorInit();
        ArgParse         p      = ArgParseInit("prog", NULL, &a);
        Zstr             listen = NULL;
        ArgRequired(&p, "-l", "--listen", &listen, "host:port");
        char  *argv[] = {(char *)"prog", (char *)"--listen"};
        DefaultAllocator a      = DefaultAllocatorInit();
        ArgParse         p      = ArgParseInit("prog", NULL, &a);
        Zstr             listen = NULL;
        ArgRequired(&p, "-l", "--listen", &listen, "host:port");
        char  *argv[] = {(char *)"prog", (char *)"-lhost"};
        ArgParse         p = ArgParseInit("cat", NULL, &a);
    
        Zstr file = NULL;
        ArgPositional(&p, "file", &file, "input file");
        ArgParse         p = ArgParseInit("prog", "test prog", &a);
    
        Zstr required = NULL;
        ArgRequired(&p, "-l", "--listen", &required, "host:port");
    }
    
    static bool help_equals(ArgParse *p, Zstr expected) {
        DefaultAllocator a   = DefaultAllocatorInit();
        Str              out = StrInit(&a);
        ArgParse         p = ArgParseInit("prog", "test prog", &a);
    
        Zstr src     = NULL;
        Zstr listen  = NULL;
        u32  timeout = 0;
    
        Zstr src     = NULL;
        Zstr listen  = NULL;
        u32  timeout = 0;
        bool verbose = false;
        ArgFlag(&p, "-v", "--verbose", &verbose, "be loud");
    
        Zstr expected =
            "prog -- test prog\n"
            "\n"
        ArgParse         p = ArgParseInit("prog", NULL, &a);
    
        Zstr listen = NULL;
        ArgRequired(&p, "-l", "--listen", &listen, "host:port");
        // [OPTIONS] DOES appear. Use that fact: it is a flag, so any_option
        // becomes true via the synthetic spec.
        Zstr expected =
            "prog\n"
            "\n"
        ArgParse         p = ArgParseInit("cp", NULL, &a);
    
        Zstr from = NULL;
        Zstr to   = NULL;
        ArgPositional(&p, "from", &from, "source path");
    
        Zstr from = NULL;
        Zstr to   = NULL;
        ArgPositional(&p, "from", &from, "source path");
        ArgPositional(&p, "to", &to, "dest path");
        ArgPositional(&p, "to", &to, "dest path");
    
        Zstr expected =
            "cp\n"
            "\n"
        ArgFlag(&p, "-q", NULL, &quiet, "quiet");
    
        Zstr expected =
            "prog\n"
            "\n"
        ArgParse         p = ArgParseInit("prog", NULL, &a);
    
        Zstr mode = NULL;
        ArgOptional(&p, NULL, "--mode", &mode, "");
    
        // "      --mode <MODE>" width = 19, widest, pad to 21.
        Zstr expected =
            "prog\n"
            "\n"
    
    // True iff `needle` occurs as a substring of `hay` (a Str body).
    static bool str_contains(Str *hay, Zstr needle) {
        u64  hn  = StrLen(hay);
        Zstr beg = StrBegin(hay);
    static bool str_contains(Str *hay, Zstr needle) {
        u64  hn  = StrLen(hay);
        Zstr beg = StrBegin(hay);
        u64  nn  = ZstrLen(needle);
        if (nn == 0)
    // ----------------------------------------------------------------------------
    
    static bool run_u32(Zstr text, u32 *out, ArgRun *rc) {
        DefaultAllocator a = DefaultAllocatorInit();
        ArgParse         p = ArgParseInit("prog", NULL, &a);
    }
    
    static bool run_u64(Zstr text, u64 *out, ArgRun *rc) {
        DefaultAllocator a = DefaultAllocatorInit();
        ArgParse         p = ArgParseInit("prog", NULL, &a);
        DefaultAllocator a = DefaultAllocatorInit();
        ArgParse         p = ArgParseInit("prog", NULL, &a);
        Zstr             s = NULL;
        ArgOptional(&p, NULL, "--name", &s, "n");
        char  *argv[] = {(char *)"prog", (char *)"--name", (char *)"carol"};
        DefaultAllocator a = DefaultAllocatorInit();
        ArgParse         p = ArgParseInit("prog", NULL, &a);
        Zstr             v = NULL;
        ArgRequired(&p, "-l", "--listen", &v, "addr");
        Str  help = StrInit(&a);
        DefaultAllocator a = DefaultAllocatorInit();
        ArgParse         p = ArgParseInit("prog", NULL, &a);
        Zstr             v = NULL;
        ArgRequired(&p, NULL, "--read-only", &v, "mode");
        Str  help = StrInit(&a);
        DefaultAllocator a = DefaultAllocatorInit();
        ArgParse         p = ArgParseInit("prog", NULL, &a);
        Zstr             v = NULL;
        ArgRequired(&p, NULL, "--port", &v, "p");
        Str  help = StrInit(&a);
        DefaultAllocator a = DefaultAllocatorInit();
        ArgParse         p = ArgParseInit("prog", NULL, &a);
        Zstr             v = NULL;
        ArgRequired(&p, "-x", NULL, &v, "x");
        Str  help = StrInit(&a);
        DefaultAllocator a = DefaultAllocatorInit();
        ArgParse         p = ArgParseInit("prog", NULL, &a);
        Zstr             v = NULL;
        ArgRequired(&p, NULL, "--ip6", &v, "x");
        Str  help = StrInit(&a);
        DefaultAllocator a = DefaultAllocatorInit();
        ArgParse         p = ArgParseInit("prog", NULL, &a);
        Zstr             v = NULL;
        ArgRequired(&p, NULL, "--gzip", &v, "x");
        Str  help = StrInit(&a);
        DefaultAllocator a = DefaultAllocatorInit();
        ArgParse         p = ArgParseInit("prog", NULL, &a);
        Zstr             v = NULL;
        ArgRequired(&p, NULL, "--abc", &v, "x");
        Str  help = StrInit(&a);
        DefaultAllocator a = DefaultAllocatorInit();
        ArgParse         p = ArgParseInit("cp", NULL, &a);
        Zstr             s = NULL;
        ArgPositional(&p, "source", &s, "from");
        Str  help = StrInit(&a);
        DefaultAllocator a = DefaultAllocatorInit();
        ArgParse         p = ArgParseInit("prog", NULL, &a);
        Zstr             v = NULL;
        ArgRequired(&p, "-l", "--listen", &v, "addr");
        Str  help = StrInit(&a);
        DefaultAllocator a = DefaultAllocatorInit();
        ArgParse         p = ArgParseInit("prog", NULL, &a);
        Zstr             v = NULL;
        ArgRequired(&p, "-l", "--listen", &v, "addr");
        Str  help = StrInit(&a);
        ArgParse         p  = ArgParseInit("prog", NULL, &a);
        bool             aa = false;
        Zstr             bb = NULL;
        ArgFlag(&p, "-a", "--a", &aa, "AAA");
        ArgRequired(&p, NULL, "--a-very-long-option-name", &bb, "BBB");
        ArgParse         p = ArgParseInit("prog", NULL, &a);
    
        Zstr listen = NULL;
        ArgRequired(&p, "-l", "--listen", &listen, "host:port");
    
        u32  verbose = 0;
        Zstr listen  = NULL;
        ArgCount(&p, "-v", "--verbose", &verbose, "v");
        ArgRequired(&p, "-l", "--listen", &listen, "host:port");
        ArgParse         p = ArgParseInit("cp", NULL, &a);
    
        Zstr from = NULL;
        Zstr to   = NULL;
        ArgPositional(&p, "from", &from, "source path");
    
        Zstr from = NULL;
        Zstr to   = NULL;
        ArgPositional(&p, "from", &from, "source path");
        ArgPositional(&p, "to", &to, "dest path");
        ArgPositional(&p, "to", &to, "dest path");
    
        Zstr expected =
            "cp\n"
            "\n"
    }
    
    static bool str_has(Str *hay, Zstr needle) {
        u64  hn  = StrLen(hay);
        Zstr beg = StrBegin(hay);
    static bool str_has(Str *hay, Zstr needle) {
        u64  hn  = StrLen(hay);
        Zstr beg = StrBegin(hay);
        u64  nn  = ZstrLen(needle);
        if (nn == 0)
        ArgParse         p = ArgParseInit("prog", NULL, &a);
    
        Zstr x = NULL;
        ArgPositional(&p, "x", &x, "");
        ArgParse         p = ArgParseInit("prog", NULL, &a);
    
        Zstr listen = NULL;
        ArgRequired(&p, "-l", "--listen", &listen, "host:port");
        name[128] = '\0';
    
        Zstr v = NULL;
        ArgRequired(&p, NULL, name, &v, "x");
        ArgParse p = ArgParseInit("prog", "an about line", adbg);
    
        Zstr listen   = NULL;
        u32  timeout  = 0;
        bool verbose  = false;
        u32  timeout  = 0;
        bool verbose  = false;
        Zstr hostname = NULL;
        ArgRequired(&p, "-l", "--listen", &listen, "host:port to listen on");
        ArgOptional(&p, NULL, "--timeout", &timeout, "connection timeout");
    
        DateTime b = {0};
        Zstr     p = StrBegin(&s);
        StrReadFmt(p, "{}", b);
    // Parse an externally-supplied ISO string directly.
    static bool test_iso_read_direct(void) {
        Zstr     in = "2026-06-26T17:34:11-07:00";
        DateTime d  = {0};
        StrReadFmt(in, "{}", d);
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Allocator/Heap.h>
    #include <Misra/Std/Container/Graph.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Graph.h>
    #include <Misra/Std/Container/Map.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Graph.h>
    #include <Misra/Std/Log.h>
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        typedef Graph(Zstr) ZstrGraph;
        ZstrGraph graph = GraphInit(&alloc);
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Float.h>
    #include <Misra/Std/Container/Int.h>
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Float.h>
    #include <Misra/Std/Container/Int.h>
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Float.h>
    #include <Misra/Std/Container/Int.h>
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        FloatFromStr((Zstr)NULL, ALLOCATOR_OF(&alloc));
        DefaultAllocatorDeinit(&alloc);
        return false;
    
        Float value = FloatInit(ALLOCATOR_OF(&alloc));
        FloatTryFromStr(&value, (Zstr)NULL);
        FloatDeinit(&value);
        DefaultAllocatorDeinit(&alloc);
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Allocator/Heap.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Memory.h>
    // owns the storage and needs a writable handle to feed into a raw `char *`
    // struct field, so the cast is correct here.
    static inline char *ZstrDupAlloc(Zstr s) {
        return (char *)zstr_dup(s, fixture_alloc());
    }
    // only proves the container's deep-copy hooks call user destructors against
    // independently-allocated payloads.
    ComplexItem InitComplexItem(Zstr name, int *values, size num_values) {
        ComplexItem item = {0};
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Log.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecRegexMatch(&source, (Zstr)NULL);
        BitVecDeinit(&source);
        DefaultAllocatorDeinit(&alloc);
    #include <Misra/Std/Container/BitVec.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Container/Str.h>
    
        // Convert from string
        Zstr   str = "1011";
        BitVec bv;
        bool   ok = BitVecTryFromStr(&bv, str, ALLOCATOR_OF(&alloc));
    
        // Test string round-trip
        Zstr patterns[] = {"101", "1111000011110000", "1", "0", "10101010", "01010101"};
    
        for (size i = 0; i < sizeof(patterns) / sizeof(patterns[0]); i++) {
        // Test specific bit patterns with exact expectations
        struct {
            Zstr pattern;
            u64  expected_value;
            u8   expected_bytes[8];
    
        // Test NULL string - should abort
        BitVecFromStr((Zstr)NULL, ALLOCATOR_OF(&alloc));
    
        DefaultAllocatorDeinit(&alloc);
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Int.h>
    #include <Misra/Std/Log.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra/Std/Container/Int.h>
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Zstr digits = "123456789012345678901234567890";
        Int  value  = IntFromStr(digits, ALLOCATOR_OF(&alloc));
        Str  text   = IntToStr(&value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Zstr hex   = "deadbeefcafebabe1234";
        Int  value = IntFromHexStr(hex, ALLOCATOR_OF(&alloc));
        Str  text  = IntToHexStr(&value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        IntFromBinary((Zstr)NULL, ALLOCATOR_OF(&alloc));
        DefaultAllocatorDeinit(&alloc);
        return false;
    
        Int value = IntInit(ALLOCATOR_OF(&alloc));
        IntTryFromBinary(&value, (Zstr)NULL);
        IntDeinit(&value);
        DefaultAllocatorDeinit(&alloc);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        IntFromStr((Zstr)NULL, ALLOCATOR_OF(&alloc));
        DefaultAllocatorDeinit(&alloc);
        return false;
    
        Int value = IntInit(ALLOCATOR_OF(&alloc));
        IntTryFromStr(&value, (Zstr)NULL);
        IntDeinit(&value);
        DefaultAllocatorDeinit(&alloc);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        IntFromStrRadix((Zstr)NULL, 10, ALLOCATOR_OF(&alloc));
        DefaultAllocatorDeinit(&alloc);
        return false;
    
        Int value = IntInit(ALLOCATOR_OF(&alloc));
        IntTryFromStrRadix(&value, (Zstr)NULL, 10);
        IntDeinit(&value);
        DefaultAllocatorDeinit(&alloc);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        IntFromOctStr((Zstr)NULL, ALLOCATOR_OF(&alloc));
        DefaultAllocatorDeinit(&alloc);
        return false;
    
        Int value = IntInit(ALLOCATOR_OF(&alloc));
        IntTryFromOctStr(&value, (Zstr)NULL);
        IntDeinit(&value);
        DefaultAllocatorDeinit(&alloc);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        IntFromHexStr((Zstr)NULL, ALLOCATOR_OF(&alloc));
        DefaultAllocatorDeinit(&alloc);
        return false;
    
        Int value = IntInit(ALLOCATOR_OF(&alloc));
        IntTryFromHexStr(&value, (Zstr)NULL);
        IntDeinit(&value);
        DefaultAllocatorDeinit(&alloc);
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
    // the extending-io guide.
    bool _write_Point2D(Str *o, FmtInfo *info, Point2D *p);
    Zstr _read_Point2D(Zstr i, FmtInfo *info, Point2D *p);
    bool _write_Bounds(Str *o, FmtInfo *info, Bounds *b);
    Zstr _read_Bounds(Zstr i, FmtInfo *info, Bounds *b);
    Zstr _read_Point2D(Zstr i, FmtInfo *info, Point2D *p);
    bool _write_Bounds(Str *o, FmtInfo *info, Bounds *b);
    Zstr _read_Bounds(Zstr i, FmtInfo *info, Bounds *b);
    bool _write_Region(Str *o, FmtInfo *info, Region *r);
    Zstr _read_Region(Zstr i, FmtInfo *info, Region *r);
    Zstr _read_Bounds(Zstr i, FmtInfo *info, Bounds *b);
    bool _write_Region(Str *o, FmtInfo *info, Region *r);
    Zstr _read_Region(Zstr i, FmtInfo *info, Region *r);
    
    bool _write_Point2D(Str *o, FmtInfo *info, Point2D *p) {
    }
    
    Zstr _read_Point2D(Zstr i, FmtInfo *info, Point2D *p) {
        (void)info;
        if (!i || !p) {
    }
    
    Zstr _read_Bounds(Zstr i, FmtInfo *info, Bounds *b) {
        (void)info;
        if (!i || !b) {
    }
    
    Zstr _read_Region(Zstr i, FmtInfo *info, Region *r) {
        (void)info;
        if (!i || !r) {
        WriteFmt("Testing user-type read through IOFMT_USER_CASE_\n");
    
        Zstr    in = "(42, -9)";
        Point2D p  = {0};
        StrReadFmt(in, "{}", p);
    
        bool ok = StrAppendFmt(&out, "{}", src);
        Zstr in = StrBegin(&out);
        StrReadFmt(in, "{}", dst);
        ok = ok && (dst.x == src.x) && (dst.y == src.y);
    
        bool ok = StrAppendFmt(&out, "{}", src);
        Zstr in = StrBegin(&out);
        StrReadFmt(in, "{}", dst);
    
        bool ok = StrAppendFmt(&out, "{}", src);
        Zstr in = StrBegin(&out);
        StrReadFmt(in, "{}", dst);
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/BitVec.h>
        bool success = true;
    
        Zstr str = "Hello";
        StrAppendFmt(&output, "{}", str);
        success = success && (ZstrCompare(StrBegin(&output), "Hello") == 0);
        StrClear(&output);
    
        Zstr empty = "";
        StrAppendFmt(&output, "{}", empty);
        success = success && (StrLen(&output) == 0);
        StrClear(&output);
    
        Zstr str = "abc";
        StrAppendFmt(&output, "{5}", str);
        success = success && (ZstrCompare(StrBegin(&output), "  abc") == 0);
        bool success = true;
    
        Zstr hello = "Hello";
        i32  num   = 42;
        f64  pi    = 3.14;
        bool success = true;
    
        Zstr mixed_case = "MiXeD CaSe";
        StrAppendFmt(&output, "{c}", mixed_case);
        success = success && (ZstrCompare(StrBegin(&output), "MiXeD CaSe") == 0);
    
    // Helper: decode one "\\xHL" escape and return the produced char (0 on fail).
    static char decode_hex_escape(Zstr lit) {
        Zstr p = lit;
        return ZstrProcessEscape(&p);
    // Helper: decode one "\\xHL" escape and return the produced char (0 on fail).
    static char decode_hex_escape(Zstr lit) {
        Zstr p = lit;
        return ZstrProcessEscape(&p);
    }
    // changes the token boundary into an unparseable token (or a zero-length
    // token) leaves the sentinel in place instead of the expected value.
    static bool read_float_equals(Zstr input, Zstr expected) {
        DefaultAllocator alloc = DefaultAllocatorInit();
    }
    
    static bool roundtrip_eq(Zstr path, Zstr expect) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        File             f     = FileOpen(path, "r");
        // argc = 1: only one argument is allowed even though two placeholders
        // appear in the format.
        Zstr out = str_read_fmt("3-4", "{}-{}", argv, 1);
    
        // Real: rejects the second placeholder -> NULL, and b stays untouched.
    static bool test_m1_invalid_spec_leaves_dest(void) {
        i32  val = 77;
        Zstr out = READ1("5", "{q}", TO_TYPE_SPECIFIC_IO(i32, &val));
        // Real: parse fails -> NULL, val unchanged.
        return out == NULL && val == 77;
    static bool test_m1_char_spec_then_literal(void) {
        u8   ch  = 0;
        Zstr in  = "AZ";
        Zstr out = READ1(in, "{c}Z", TO_TYPE_SPECIFIC_IO(u8, &ch));
        // Real: reads 'A' as the {c} field, matches literal 'Z', consumes all.
        u8   ch  = 0;
        Zstr in  = "AZ";
        Zstr out = READ1(in, "{c}Z", TO_TYPE_SPECIFIC_IO(u8, &ch));
        // Real: reads 'A' as the {c} field, matches literal 'Z', consumes all.
        return out == in + 2 && ch == 'A';
    
        // 50 'A's inside quotes.
        Zstr in = "\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"";
    
        Str  s   = StrInit(&alloc);
    
        Str  s   = StrInit(&alloc);
        Zstr out = READ1(in, "{s}", TO_TYPE_SPECIFIC_IO(Str, &s));
    
        bool ok = (out != NULL) && (StrLen(&s) == 50);
    static bool test_m1_raw_u8(void) {
        u8   v   = 0;
        Zstr in  = "\x07";
        Zstr out = READ1(in, "{<1r}", TO_TYPE_SPECIFIC_IO(u8, &v));
        return out == in + 1 && v == 0x07;
        u8   v   = 0;
        Zstr in  = "\x07";
        Zstr out = READ1(in, "{<1r}", TO_TYPE_SPECIFIC_IO(u8, &v));
        return out == in + 1 && v == 0x07;
    }
    static bool test_m1_raw_i8(void) {
        i8   v   = 0;
        Zstr in  = "\x07";
        Zstr out = READ1(in, "{<1r}", TO_TYPE_SPECIFIC_IO(i8, &v));
        return out == in + 1 && v == 0x07;
        i8   v   = 0;
        Zstr in  = "\x07";
        Zstr out = READ1(in, "{<1r}", TO_TYPE_SPECIFIC_IO(i8, &v));
        return out == in + 1 && v == 0x07;
    }
    static bool test_m1_raw_u16_le(void) {
        u16  v   = 0;
        Zstr in  = "\x34\x12"; // LE -> 0x1234
        Zstr out = READ1(in, "{<2r}", TO_TYPE_SPECIFIC_IO(u16, &v));
        return out == in + 2 && v == 0x1234;
        u16  v   = 0;
        Zstr in  = "\x34\x12"; // LE -> 0x1234
        Zstr out = READ1(in, "{<2r}", TO_TYPE_SPECIFIC_IO(u16, &v));
        return out == in + 2 && v == 0x1234;
    }
    static bool test_m1_raw_i16_be(void) {
        i16  v   = 0;
        Zstr in  = "\x12\x34"; // BE -> 0x1234
        Zstr out = READ1(in, "{>2r}", TO_TYPE_SPECIFIC_IO(i16, &v));
        return out == in + 2 && v == 0x1234;
        i16  v   = 0;
        Zstr in  = "\x12\x34"; // BE -> 0x1234
        Zstr out = READ1(in, "{>2r}", TO_TYPE_SPECIFIC_IO(i16, &v));
        return out == in + 2 && v == 0x1234;
    }
    static bool test_m1_raw_u32_le(void) {
        u32  v   = 0;
        Zstr in  = "\xEF\xBE\xAD\xDE"; // LE -> 0xDEADBEEF
        Zstr out = READ1(in, "{<4r}", TO_TYPE_SPECIFIC_IO(u32, &v));
        return out == in + 4 && v == 0xDEADBEEFu;
        u32  v   = 0;
        Zstr in  = "\xEF\xBE\xAD\xDE"; // LE -> 0xDEADBEEF
        Zstr out = READ1(in, "{<4r}", TO_TYPE_SPECIFIC_IO(u32, &v));
        return out == in + 4 && v == 0xDEADBEEFu;
    }
    static bool test_m1_raw_i32_be(void) {
        i32  v   = 0;
        Zstr in  = "\x12\x34\x56\x78"; // BE -> 0x12345678
        Zstr out = READ1(in, "{>4r}", TO_TYPE_SPECIFIC_IO(i32, &v));
        return out == in + 4 && v == 0x12345678;
        i32  v   = 0;
        Zstr in  = "\x12\x34\x56\x78"; // BE -> 0x12345678
        Zstr out = READ1(in, "{>4r}", TO_TYPE_SPECIFIC_IO(i32, &v));
        return out == in + 4 && v == 0x12345678;
    }
    static bool test_m1_raw_u64_le(void) {
        u64  v   = 0;
        Zstr in  = "\x08\x07\x06\x05\x04\x03\x02\x01"; // LE -> 0x0102030405060708
        Zstr out = READ1(in, "{<8r}", TO_TYPE_SPECIFIC_IO(u64, &v));
        return out == in + 8 && v == 0x0102030405060708ull;
        u64  v   = 0;
        Zstr in  = "\x08\x07\x06\x05\x04\x03\x02\x01"; // LE -> 0x0102030405060708
        Zstr out = READ1(in, "{<8r}", TO_TYPE_SPECIFIC_IO(u64, &v));
        return out == in + 8 && v == 0x0102030405060708ull;
    }
    static bool test_m1_raw_i64_be(void) {
        i64  v   = 0;
        Zstr in  = "\x01\x02\x03\x04\x05\x06\x07\x08"; // BE -> 0x0102030405060708
        Zstr out = READ1(in, "{>8r}", TO_TYPE_SPECIFIC_IO(i64, &v));
        return out == in + 8 && v == 0x0102030405060708ll;
        i64  v   = 0;
        Zstr in  = "\x01\x02\x03\x04\x05\x06\x07\x08"; // BE -> 0x0102030405060708
        Zstr out = READ1(in, "{>8r}", TO_TYPE_SPECIFIC_IO(i64, &v));
        return out == in + 8 && v == 0x0102030405060708ll;
    }
        } got = {0};
    
        Zstr in  = "\xEF\xBE\xAD\xDE"; // LE bytes -> bit pattern 0xDEADBEEF
        Zstr out = READ1(in, "{<4r}", TO_TYPE_SPECIFIC_IO(f32, &got.f));
    
        Zstr in  = "\xEF\xBE\xAD\xDE"; // LE bytes -> bit pattern 0xDEADBEEF
        Zstr out = READ1(in, "{<4r}", TO_TYPE_SPECIFIC_IO(f32, &got.f));
    
        return out == in + 4 && got.u == 0xDEADBEEFu;
        } got = {0};
    
        Zstr in  = "\x08\x07\x06\x05\x04\x03\x02\x01"; // LE -> 0x0102030405060708
        Zstr out = READ1(in, "{<8r}", TO_TYPE_SPECIFIC_IO(f64, &got.f));
    
        Zstr in  = "\x08\x07\x06\x05\x04\x03\x02\x01"; // LE -> 0x0102030405060708
        Zstr out = READ1(in, "{<8r}", TO_TYPE_SPECIFIC_IO(f64, &got.f));
    
        return out == in + 8 && got.u == 0x0102030405060708ull;
    //     real guard is false; either swap to != makes the guard true and errors. ---
    static bool test_m11_hex_two_digits_not_truncated(void) {
        Zstr p = "\\x41"; // 'A'
        char c = ZstrProcessEscape(&p);
        return c == 'A';
    //     0x41 = 65 != 42, so the decoded byte mismatches. ---
    static bool test_m11_hex_value_is_decoded_not_42(void) {
        Zstr p = "\\x41"; // must yield 65 ('A'), not 42 ('*')
        char c = ZstrProcessEscape(&p);
        return c == (char)65;
    // is actually consumed (255 != 42).
    static bool test_m11_hex_ff(void) {
        Zstr p = "\\xff";
        char c = ZstrProcessEscape(&p);
        return (unsigned char)c == 0xFFu;
    //     error branch and returns 0; real returns the byte. ---
    static bool test_m11_hex_valid_not_rejected(void) {
        Zstr p = "\\x41";
        return ZstrProcessEscape(&p) == 'A';
    }
    //     0x41 -> 65, distinct from 42. ---
    static bool test_m11_hex_result_assigned_from_value(void) {
        Zstr p = "\\x41";
        return ZstrProcessEscape(&p) == (char)65;
    }
    // the hex_byte<0 path so the lt mutants have a contrasting branch covered.
    static bool test_m11_hex_invalid_returns_zero(void) {
        Zstr p = "\\xZZ";
        return ZstrProcessEscape(&p) == 0;
    }
    
        BitVec bv = BitVecInit(alloc_base);
        Zstr   z  = "0x1";
        StrReadFmt(z, "{}", bv);
    
        BitVec bv = BitVecInit(alloc_base);
        Zstr   z  = "0xDEAD";
        StrReadFmt(z, "{}", bv);
    
        BitVec bv = BitVecInit(alloc_base);
        Zstr   z  = "0xDEAD";
        StrReadFmt(z, "{}", bv);
    
        BitVec bv = BitVecInit(alloc_base);
        Zstr   z  = "0o1";
        StrReadFmt(z, "{}", bv);
    
        BitVec bv = BitVecInit(alloc_base);
        Zstr   z  = "0o10";
        StrReadFmt(z, "{}", bv);
    
        BitVec bv = BitVecInit(alloc_base);
        Zstr   z  = "0o755";
        StrReadFmt(z, "{}", bv);
        Str              output = StrInit(&alloc);
    
        Zstr s = "AB"; // 0x41 0x42
        StrAppendFmt(&output, "{x}", s);
        bool ok = (ZstrCompare(StrBegin(&output), "0x41 0x42") == 0);
        Str              output = StrInit(&alloc);
    
        Zstr s = "Z"; // 0x5a
        StrAppendFmt(&output, "{x}", s);
        bool ok = (ZstrCompare(StrBegin(&output), "0x5a") == 0);
        Str              output = StrInit(&alloc);
    
        Zstr s = "\xab"; // single byte 0xab
        StrAppendFmt(&output, "{x}", s);
        bool ok = (ZstrCompare(StrBegin(&output), "0xab") == 0);
        Str              output = StrInit(&alloc);
    
        Zstr s = "\xab";
        StrAppendFmt(&output, "{X}", s);
        bool ok = (ZstrCompare(StrBegin(&output), "0xAB") == 0);
        Str              output = StrInit(&alloc);
    
        Zstr s = "\x05"; // single byte 0x05
        StrAppendFmt(&output, "{x}", s);
        bool ok = (ZstrCompare(StrBegin(&output), "0x05") == 0);
        Str              output = StrInit(&alloc);
    
        Zstr s = "\xfe";
        StrAppendFmt(&output, "{x}", s);
        bool ok = (ZstrCompare(StrBegin(&output), "0xfe") == 0);
        Str              output = StrInit(&alloc);
    
        Zstr s = "Hello";
        StrAppendFmt(&output, "{.3}", s);
        bool ok = (ZstrCompare(StrBegin(&output), "Hel") == 0);
        Str              output = StrInit(&alloc);
    
        Zstr s = "Hi";
        StrAppendFmt(&output, "{.10}", s);
        bool ok = (ZstrCompare(StrBegin(&output), "Hi") == 0);
        Str              output = StrInit(&alloc);
    
        Zstr s = "Hello";
        StrAppendFmt(&output, "{.0}", s);
        bool ok = (StrLen(&output) == 0);
        Str              output = StrInit(&alloc);
    
        Zstr s = "Hello";
        StrAppendFmt(&output, "{.1}", s);
        bool ok = (ZstrCompare(StrBegin(&output), "H") == 0);
        Str              output = StrInit(&alloc);
    
        Zstr s = "Hi";
        StrAppendFmt(&output, "abc{>10}", s);
        bool ok = (ZstrCompare(StrBegin(&output), "        abcHi") == 0);
        Str              output = StrInit(&alloc);
    
        Zstr s = "Hi";
        StrAppendFmt(&output, "xy{<10}", s);
        bool ok = (ZstrCompare(StrBegin(&output), "xyHi        ") == 0);
        Str              output = StrInit(&alloc);
    
        Zstr s = "";
        StrAppendFmt(&output, "{>5}", s);
        bool ok = (ZstrCompare(StrBegin(&output), "     ") == 0);
    // ---------------------------------------------------------------------------
    static bool test_m14_hex_prefix_uses_first_char_flag(void) {
        Zstr z = "0x1f";
        u8   v = 0;
        StrReadFmt(z, "{}", v);
    // ---------------------------------------------------------------------------
    static bool test_m14_slice_length_is_difference(void) {
        Zstr z = " 5";
        u8   v = 0;
        StrReadFmt(z, "{}", v);
    // ---------------------------------------------------------------------------
    static bool test_m14_prefix_guard_len_gate(void) {
        Zstr z = "0xff";
        u8   v = 0;
        StrReadFmt(z, "{}", v);
    // ---------------------------------------------------------------------------
    static bool test_m14_prefix_guard_letters(void) {
        Zstr z = "05";
        u8   v = 0;
        StrReadFmt(z, "{}", v);
    // The 42-mutant stores '*' instead.
    static bool test_m18_bad_nibble_salvage(void) {
        Zstr z = "\\xZZ";            // '\', 'x', 'Z', 'Z'
        u8   v = 0;
        StrReadFmt(z, "{c}", v);
    // the 42-mutant on 1607 stores '*'.
    static bool test_m18_force_lowercase(void) {
        Zstr z = "A";
        u8   v = 0;
        StrReadFmt(z, "{a}", v);
    // the 42-mutant on 1607 stores '*'.
    static bool test_m18_force_uppercase(void) {
        Zstr z = "a";
        u8   v = 0;
        StrReadFmt(z, "{A}", v);
    static bool test_m18_buffer_size_stop(void) {
        u8   buf[4] = {0, 0, 0, 0};
        Zstr z      = "AB";
        StrReadFmt(z, "{c}", buf[0]);
        bool ok = (buf[0] == 'A');
    static bool test_m19_neg_inf_lower(void) {
        f64  v    = 123.0;
        Zstr z    = "-inf";
        Zstr orig = z;
        StrReadFmt(z, "{}", v);
        f64  v    = 123.0;
        Zstr z    = "-inf";
        Zstr orig = z;
        StrReadFmt(z, "{}", v);
        // Real: consumed (z advanced) and v is -inf. Mutant: not consumed.
    static bool test_m19_neg_inf_upper(void) {
        f64  v    = 7.0;
        Zstr z    = "-Inf";
        Zstr orig = z;
        StrReadFmt(z, "{}", v);
        f64  v    = 7.0;
        Zstr z    = "-Inf";
        Zstr orig = z;
        StrReadFmt(z, "{}", v);
        return (z != orig) && F64IsInf(v) && (v < 0.0);
    static bool test_m19_dash_clause_not_minus(void) {
        f64  v = 0.0;
        Zstr z = "5inf";
        StrReadFmt(z, "{}", v);
        // Real: advanced by 1 -> *z == 'i'. Mutant: advanced by 4 -> *z == '\0'.
    static bool test_m19_inf_branch_strtof64_truthy(void) {
        f64  v    = 55.0;
        Zstr z    = "info";
        Zstr orig = z;
        StrReadFmt(z, "{}", v);
        f64  v    = 55.0;
        Zstr z    = "info";
        Zstr orig = z;
        StrReadFmt(z, "{}", v);
        // Real: not consumed (z unchanged). Mutant: consumed (z advanced).
    static bool test_m19_token_length_leading_space(void) {
        f64  v = -1.0;
        Zstr z = " 3.14";
        StrReadFmt(z, "{}", v);
        // Real: v == 3.14. Mutant: parse fails, v left at -1.0.
    static bool test_m19_numeric_string_guard(void) {
        f64  v    = 88.0;
        Zstr z    = "1f";
        Zstr orig = z;
        StrReadFmt(z, "{}", v);
        f64  v    = 88.0;
        Zstr z    = "1f";
        Zstr orig = z;
        StrReadFmt(z, "{}", v);
        // Real: rejected, not consumed (z unchanged). Mutant: consumed.
    
        f64  v = SENTINEL;
        Zstr z = "0x";
        StrReadFmt(z, "{}", v);
    
        f64  v = SENTINEL;
        Zstr z = "0b";
        StrReadFmt(z, "{}", v);
    
        f64  v = SENTINEL;
        Zstr z = "0o";
        StrReadFmt(z, "{}", v);
    
        f64  v = SENTINEL;
        Zstr z = "0X1F";
        StrReadFmt(z, "{}", v);
    
        f64  v = SENTINEL;
        Zstr z = "0B11";
        StrReadFmt(z, "{}", v);
    
        f64  v = SENTINEL;
        Zstr z = "0O7";
        StrReadFmt(z, "{}", v);
    
        f64  v = SENTINEL;
        Zstr z = "12.5";
        StrReadFmt(z, "{}", v);
    
        f64  v = SENTINEL;
        Zstr z = "0x1f";
        StrReadFmt(z, "{}", v);
        Float val     = FloatInit(alloc_base);
    
        Zstr z = "3.5;";
        StrReadFmt(z, "{};", val);
        Float val     = FloatInit(alloc_base);
    
        Zstr z = "12.25";
        StrReadFmt(z, "{}", val);
        Float val     = FloatInit(alloc_base);
    
        Zstr z = "1.5e2!";
        StrReadFmt(z, "{e}!", val);
        Float val     = FloatInit(alloc_base);
    
        Zstr z = "-0.25";
        StrReadFmt(z, "{}", val);
    
        BitVec bv = BitVecInit(alloc_base);
        Zstr   z  = "0x3ff";
        StrReadFmt(z, "{}", bv);
    
        BitVec bv = BitVecInit(alloc_base);
        Zstr   z  = "0xff";
        StrReadFmt(z, "{}", bv);
    
        BitVec bv = BitVecInit(alloc_base);
        Zstr   z  = "0x10000";
        StrReadFmt(z, "{}", bv);
    
    static bool test_m28_fwrite_roundtrip_string(void) {
        Zstr path = "io_mutants28_str.txt"; // CWD-relative: portable (no /tmp on Windows)
        File f    = FileOpen(path, "w");
        if (!FileIsOpen(&f)) {
        }
    
        Zstr s   = "World";
        bool ret = FWriteFmt(&f, "Hello {}!", s);
        FileClose(&f);
    
    static bool test_m28_fwrite_roundtrip_int(void) {
        Zstr path = "io_mutants28_int.txt"; // CWD-relative: portable (no /tmp on Windows)
        File f    = FileOpen(path, "w");
        if (!FileIsOpen(&f)) {
    // compare still holds (543:83) with the '\n' counted.
    static bool test_m28_fwriteln_roundtrip(void) {
        Zstr path = "io_mutants28_ln.txt"; // CWD-relative: portable (no /tmp on Windows)
        File f    = FileOpen(path, "w");
        if (!FileIsOpen(&f)) {
    static bool test_m29_hexbyte_printable_roundtrip(void) {
        u8   v = 0;
        Zstr z = "\\x41";
        StrReadFmt(z, "{c}", v);
        return v == 0x41;
    static bool test_m29_hexbyte_high_nibble_zero(void) {
        u8   v = 0;
        Zstr z = "\\x01";
        StrReadFmt(z, "{c}", v);
        return v == 0x01;
    static bool test_m29_hexbyte_low_nibble_zero(void) {
        u8   v = 0;
        Zstr z = "\\x10";
        StrReadFmt(z, "{c}", v);
        return v == 0x10;
    static bool test_m29_hexbyte_letter_nibble(void) {
        u8   v = 0;
        Zstr z = "\\x4f";
        StrReadFmt(z, "{c}", v);
        return v == 0x4f;
        Int oct = IntInit(alloc_base);
    
        Zstr z = "78";
        StrReadFmt(z, "{o}", oct);
        Str              output     = StrInit(&alloc);
    
        Zstr name = "hello";
        StrAppendFmt(&output, "{s}", ZstrIO(name, alloc_base));
    
        // "abc" is 3 chars; field width 3 -> no padding at all.
        Zstr s = "abc";
        StrAppendFmt(&out, "{3}", s);
        ok = ok && (ZstrCompare(StrBegin(&out), "abc") == 0);
    static bool test_m5_char_flag_empty_keeps_zero_init(void) {
        f32  v = -1.0f;
        Zstr z = " ";
        StrReadFmt(z, "{c}", v);
        return f32_close(v, 0.0f);
    static bool test_m5_special_lower_inf(void) { // c == 'i'
        f32  v = 0.0f;
        Zstr z = "inf";
        StrReadFmt(z, "{}", v);
        return v > 1e30f;
    static bool test_m5_special_upper_inf(void) { // c == 'I'
        f32  v = 0.0f;
        Zstr z = "INF";
        StrReadFmt(z, "{}", v);
        return v > 1e30f;
    static bool test_m5_special_lower_nan(void) { // c == 'n'
        f32  v = 0.0f;
        Zstr z = "nan";
        StrReadFmt(z, "{}", v);
        return v != v;                            // NaN is the only value not equal to itself
    static bool test_m5_special_upper_nan(void) { // c == 'N'
        f32  v = 0.0f;
        Zstr z = "NAN";
        StrReadFmt(z, "{}", v);
        return v != v;
    static bool test_m5_special_neg_inf_dash(void) { // c == '-'
        f32  v = 0.0f;
        Zstr z = "-inf";
        StrReadFmt(z, "{}", v);
        return v < -1e30f;
    static bool test_m5_special_neg_inf_c1_lower(void) { // c1 == 'i'
        f32  v = 0.0f;
        Zstr z = "-inf";
        StrReadFmt(z, "{}", v);
        return v < -1e30f;
    static bool test_m5_special_neg_inf_c1_upper(void) { // c1 == 'I'
        f32  v = 0.0f;
        Zstr z = "-INF";
        StrReadFmt(z, "{}", v);
        return v < -1e30f;
    static bool test_m5_special_value_is_not_42(void) {
        f32  v = 0.0f;
        Zstr z = "inf";
        StrReadFmt(z, "{}", v);
        return v > 1e30f; // 42.0 would fail this
    static bool test_m5_exponent_lower_with_sign(void) {
        f32  v = 0.0f;
        Zstr z = "1e+3";
        StrReadFmt(z, "{}", v);
        return f32_close(v, 1000.0f);
    static bool test_m5_exponent_upper_with_sign(void) {
        f32  v = 0.0f;
        Zstr z = "1E+3";
        StrReadFmt(z, "{}", v);
        return f32_close(v, 1000.0f);
    static bool test_m5_exponent_guard_not_le(void) {
        f32  v = 0.0f;
        Zstr z = "2e-2";
        StrReadFmt(z, "{}", v);
        return f32_close(v, 0.02f);
    static bool test_m5_exponent_plus_sign(void) {
        f32  v = 0.0f;
        Zstr z = "1e+3";
        StrReadFmt(z, "{}", v);
        return f32_close(v, 1000.0f);
    static bool test_m5_exponent_minus_sign(void) {
        f32  v = 0.0f;
        Zstr z = "1e-3";
        StrReadFmt(z, "{}", v);
        return f32_close(v, 0.001f);
    static bool test_m5_leading_sign_is_first_char(void) {
        f32  v = 0.0f;
        Zstr z = "+1.5";
        StrReadFmt(z, "{}", v);
        return f32_close(v, 1.5f);
    static bool test_m5_token_length_uses_subtraction(void) {
        f32  v = 0.0f;
        Zstr z = "  3.5";
        StrReadFmt(z, "{}", v);
        return f32_close(v, 3.5f);
    
        Int  v = IntInit(ALLOCATOR_OF(&alloc));
        Zstr z = "9z";
        StrReadFmt(z, "{}", v);
        bool ok = (IntCompare(&v, 9) == 0);
    
        Int  v = IntInit(ALLOCATOR_OF(&alloc));
        Zstr z = "5";
        StrReadFmt(z, "{}", v);
        bool ok = (IntCompare(&v, 5) == 0);
    
        Int  v = IntInit(ALLOCATOR_OF(&alloc));
        Zstr z = "+8";
        StrReadFmt(z, "{}", v);
        bool ok = (IntCompare(&v, 8) == 0);
    
        Int  v = IntFromStr("123", &alloc);
        Zstr z = "9_";
        StrReadFmt(z, "{}", v);
        bool ok = (IntCompare(&v, 123) == 0);
    
        Int  v = IntFromStr("200", &alloc);
        Zstr z = "0xFF";
        StrReadFmt(z, "{x}", v);
        bool ok = (IntCompare(&v, 200) == 0);
    
        Int  v = IntFromStr("200", &alloc);
        Zstr z = "0XFF";
        StrReadFmt(z, "{x}", v);
        bool ok = (IntCompare(&v, 200) == 0);
    
        Int  v = IntInit(ALLOCATOR_OF(&alloc));
        Zstr z = "ff";
        StrReadFmt(z, "{x}", v);
        bool ok = (IntCompare(&v, 255) == 0);
    
        Int  v = IntFromStr("5", &alloc);
        Zstr z = "0b1";
        StrReadFmt(z, "{b}", v);
        bool ok = (IntCompare(&v, 5) == 0);
    
        Int  v = IntFromStr("5", &alloc);
        Zstr z = "0B1";
        StrReadFmt(z, "{b}", v);
        bool ok = (IntCompare(&v, 5) == 0);
    
        Int  v = IntInit(ALLOCATOR_OF(&alloc));
        Zstr z = "101";
        StrReadFmt(z, "{b}", v);
        bool ok = (IntCompare(&v, 5) == 0);
    
        Int  v = IntFromStr("9", &alloc);
        Zstr z = "0o7";
        StrReadFmt(z, "{o}", v);
        bool ok = (IntCompare(&v, 9) == 0);
    
        Int  v = IntFromStr("9", &alloc);
        Zstr z = "0O7";
        StrReadFmt(z, "{o}", v);
        bool ok = (IntCompare(&v, 9) == 0);
    
        Int  v = IntInit(ALLOCATOR_OF(&alloc));
        Zstr z = "17";
        StrReadFmt(z, "{o}", v);
        bool ok = (IntCompare(&v, 15) == 0);
    
        Int  v = IntInit(ALLOCATOR_OF(&alloc));
        Zstr z = "   42";
        StrReadFmt(z, "{}", v);
        bool ok = (IntCompare(&v, 42) == 0);
        bool             ok    = true;
    
        Zstr s  = "Hello";
        bool rc = StrAppendFmt(&out, "{.9s}", s);
        ok      = ok && rc;
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        Zstr             s     = "ab";
        StrAppendFmt(&out, "{4}", s);
        bool ok = (ZstrCompare(StrBegin(&out), "  ab") == 0);
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        Zstr             s     = "abc";
        StrAppendFmt(&out, "{3}", s);
        bool ok = (ZstrCompare(StrBegin(&out), "abc") == 0);
    static bool test_zstr_hex_no_leak(void) {
        DBG_BEGIN(dbg, out);
        Zstr s = "\x01\x4f";
        StrAppendFmt(&out, "{x}", s);
        bool ok = (ZstrCompare(StrBegin(&out), "0x01 0x4f") == 0);
    static bool test_zstr_hex_nibble_no_leak(void) {
        DBG_BEGIN(dbg, out);
        Zstr s = "\x05";
        StrAppendFmt(&out, "{x}", s);
        bool ok = (ZstrCompare(StrBegin(&out), "0x05") == 0);
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        Zstr             s     = "hi";
        StrAppendFmt(&out, "{}", s);
        bool ok = (ZstrCompare(StrBegin(&out), "hi") == 0);
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        Zstr s   = "AB"; // multi-byte Zstr -> hex loop runs per byte
        Str  out = StrInit(adbg);
        bool ok  = StrAppendFmt(&out, "{x}", s);
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/BitVec.h>
        WriteFmt("Testing integer decimal reading\n");
    
        Zstr z = NULL;
    
        bool success = true;
        WriteFmt("Testing integer hexadecimal reading\n");
    
        Zstr z = NULL;
    
        bool success = true;
        WriteFmt("Testing integer binary reading\n");
    
        Zstr z = NULL;
    
        bool success = true;
        WriteFmt("Testing integer octal reading\n");
    
        Zstr z = NULL;
    
        bool success = true;
        WriteFmt("Testing basic float reading\n");
    
        Zstr z = NULL;
    
        bool success = true;
        WriteFmt("Testing scientific notation reading\n");
    
        Zstr z = NULL;
    
        bool success = true;
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Zstr z = NULL;
    
        bool success = true;
    
        {
            Zstr zs = NULL;
    
            z = "Allocator-backed";
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Zstr z = NULL;
    
        bool success = true;
        WriteFmt("Testing error handling for reading\n");
    
        Zstr z = NULL;
    
        bool success = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Zstr z = NULL;
    
        bool success = true;
        z       = "AB";
        StrReadFmt(z, "{c}", u16_val);
        bool u16_multi_pass = (ZstrCompareN((Zstr)&u16_val, "AB", 2) == 0);
        WriteFmt("u16_val multi-char test: comparing memory with 'AB', pass = {}\n", u16_multi_pass ? "true" : "false");
        WriteFmt(
        z       = "CD";
        StrReadFmt(z, "{c}", i16_val);
        bool i16_multi_pass = (ZstrCompareN((Zstr)&i16_val, "CD", 2) == 0);
        WriteFmt("i16_val multi-char test: comparing memory with 'CD', pass = {}\n", i16_multi_pass ? "true" : "false");
        success = success && i16_multi_pass;
        z       = "EFGH";
        StrReadFmt(z, "{c}", u32_val);
        bool u32_multi_pass = (ZstrCompareN((Zstr)&u32_val, "EFGH", 4) == 0);
        WriteFmt("u32_val multi-char test: comparing memory with 'EFGH', pass = {}\n", u32_multi_pass ? "true" : "false");
        success = success && u32_multi_pass;
        z       = "IJKL";
        StrReadFmt(z, "{c}", i32_val);
        bool i32_multi_pass = (ZstrCompareN((Zstr)&i32_val, "IJKL", 4) == 0);
        WriteFmt("i32_val multi-char test: comparing memory with 'IJKL', pass = {}\n", i32_multi_pass ? "true" : "false");
        success = success && i32_multi_pass;
        z       = "MNOPQRST";
        StrReadFmt(z, "{c}", u64_val);
        bool u64_multi_pass = (ZstrCompareN((Zstr)&u64_val, "MNOPQRST", 8) == 0);
        WriteFmt(
            "u64_val multi-char test: comparing memory with 'MNOPQRST', pass = {}\n",
        z       = "UVWXYZab";
        StrReadFmt(z, "{c}", i64_val);
        bool i64_multi_pass = (ZstrCompareN((Zstr)&i64_val, "UVWXYZab", 8) == 0);
        WriteFmt(
            "i64_val multi-char test: comparing memory with 'UVWXYZab', pass = {}\n",
        z       = "XY";
        StrReadFmt(z, "{c}", u32_val);
        bool xy_pass = (ZstrCompareN((Zstr)&u32_val, "XY", 2) == 0);
        WriteFmt("u32_val partial test: comparing memory with 'XY', pass = {}\n", xy_pass ? "true" : "false");
        success = success && xy_pass;
        z       = "abc";
        StrReadFmt(z, "{c}", u64_val);
        bool abc_pass = (ZstrCompareN((Zstr)&u64_val, "abc", 3) == 0);
        WriteFmt("u64_val partial test: comparing memory with 'abc', pass = {}\n", abc_pass ? "true" : "false");
        success = success && abc_pass;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Zstr z = NULL;
    
        bool success = true;
        {
            Str  result = StrInit(&alloc);
            Zstr in     = "Hello World";
    
            z = in;
        {
            Str  result = StrInit(&alloc);
            Zstr in     = "Hello World";
    
            z = in;
        {
            Str  result = StrInit(&alloc);
            Zstr in     = "hello world";
    
            z = in;
            Str  result1 = StrInit(&alloc);
            Str  result2 = StrInit(&alloc);
            Zstr in      = "hello world";
    
            z = in;
            Str  result1 = StrInit(&alloc);
            Str  result2 = StrInit(&alloc);
            Zstr in      = "hello world mighty misra";
    
            z = in;
        {
            Str  result = StrInit(&alloc);
            Zstr in     = "\"MiXeD CaSe\"";
    
            z = in;
        {
            Str  result = StrInit(&alloc);
            Zstr in     = "\"abc123XYZ\"";
    
            z = in;
        {
            Str  result = StrInit(&alloc);
            Zstr in     = "Hello World";
    
            z = in;
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Zstr z = NULL;
    
        bool success = true;
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Zstr z       = NULL;
        bool success = true;
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Zstr z       = NULL;
        bool success = true;
    // "{​{" branch), 571 ne_to_eq (*in != '{'), 577 sub_assign (rem_p -= 2).
    static bool test_m1_escaped_open_brace(void) {
        Zstr in  = "{rest";
        Zstr out = str_read_fmt(
            in,
    static bool test_m1_escaped_open_brace(void) {
        Zstr in  = "{rest";
        Zstr out = str_read_fmt(
            in,
            "{​{",
    // Reinforces 570/571/577.
    static bool test_m1_escaped_open_brace_exact(void) {
        Zstr in  = "{";
        Zstr out = str_read_fmt(
            in,
    static bool test_m1_escaped_open_brace_exact(void) {
        Zstr in  = "{";
        Zstr out = str_read_fmt(
            in,
            "{​{",
    // 585 sub_assign (rem_p -= 2).
    static bool test_m1_escaped_close_brace(void) {
        Zstr in  = "}rest";
        Zstr out = str_read_fmt(
            in,
    static bool test_m1_escaped_close_brace(void) {
        Zstr in  = "}rest";
        Zstr out = str_read_fmt(
            in,
            "}}",
    
    static bool test_m1_escaped_close_brace_exact(void) {
        Zstr in  = "}";
        Zstr out = str_read_fmt(
            in,
    static bool test_m1_escaped_close_brace_exact(void) {
        Zstr in  = "}";
        Zstr out = str_read_fmt(
            in,
            "}}",
    // decodes; the mutant `*s == '\\'` enters the error branch and returns 0.
    static bool test_m11_simple_escape_decodes(void) {
        Zstr p = "\\n";
        char c = ZstrProcessEscape(&p);
        return c == '\n';
    // on any one case mismatches.
    static bool test_m11_escape_n(void) {
        Zstr p = "\\n";
        return ZstrProcessEscape(&p) == '\n';
    }
    }
    static bool test_m11_escape_r(void) {
        Zstr p = "\\r";
        return ZstrProcessEscape(&p) == '\r';
    }
    }
    static bool test_m11_escape_t(void) {
        Zstr p = "\\t";
        return ZstrProcessEscape(&p) == '\t';
    }
    }
    static bool test_m11_escape_b(void) {
        Zstr p = "\\b";
        return ZstrProcessEscape(&p) == '\b';
    }
    }
    static bool test_m11_escape_f(void) {
        Zstr p = "\\f";
        return ZstrProcessEscape(&p) == '\f';
    }
    }
    static bool test_m11_escape_v(void) {
        Zstr p = "\\v";
        return ZstrProcessEscape(&p) == '\v';
    }
    }
    static bool test_m11_escape_a(void) {
        Zstr p = "\\a";
        return ZstrProcessEscape(&p) == '\a';
    }
    }
    static bool test_m11_escape_backslash(void) {
        Zstr p = "\\\\";
        return ZstrProcessEscape(&p) == '\\';
    }
    }
    static bool test_m11_escape_dquote(void) {
        Zstr p = "\\\"";
        return ZstrProcessEscape(&p) == '"';
    }
    }
    static bool test_m11_escape_squote(void) {
        Zstr p = "\\'";
        return ZstrProcessEscape(&p) == '\'';
    }
    // case '0' -> result = '\0'; cxx_assign_const(42) at 2216 makes it '*'.
    static bool test_m11_escape_nul(void) {
        Zstr p = "\\0";
        return ZstrProcessEscape(&p) == '\0';
    }
    // ---------------------------------------------------------------------------
    static bool test_m14_scan_stops_at_invalid_char(void) {
        Zstr z = "42!";
        u8   v = 0;
        StrReadFmt(z, "{}", v);
    // substitutes 42 ('*') for the decoded byte -- all differ from 0x41.
    static bool test_m18_hex_escape_decode(void) {
        Zstr z   = "\\x41"; // four bytes: '\', 'x', '4', '1'
        Zstr beg = z;
        u8   v   = 0;
    static bool test_m18_hex_escape_decode(void) {
        Zstr z   = "\\x41"; // four bytes: '\', 'x', '4', '1'
        Zstr beg = z;
        u8   v   = 0;
        StrReadFmt(z, "{c}", v);
    // decode and salvages the literal '\' (0x5C) instead.
    static bool test_m18_hex_escape_zero_byte(void) {
        Zstr z = "\\x00";      // '\', 'x', '0', '0'
        u8   v = 0xAA;         // poison so a no-write is detectable too
        StrReadFmt(z, "{c}", v);
    // the 42-mutant stores '*'.
    static bool test_m18_truncated_hex_escape(void) {
        Zstr z = "\\x";              // '\', 'x', then NUL
        u8   v = 0;
        StrReadFmt(z, "{c}", v);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Zstr input = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmn"; // 50 chars, no spaces/backslashes
    
        char     *out = NULL;
        FmtInfo   fmt = {0}; // max_read_len == 0 -> hits the !max_read_len branch
    
        Zstr next = _read_ZstrAlloc(input, &fmt, &arg);
        bool ok   = (next != NULL) && out && (ZstrCompare(out, input) == 0);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Zstr input = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmn"; // 50 chars
    
        char     *out = NULL;
        ZstrIOArg arg = {.value = (void *)&out, .allocator = alloc_base};
    
        Zstr next = _read_ZstrAlloc(input, NULL, &arg);
        bool ok   = (next != NULL) && out && (ZstrCompare(out, input) == 0);
    //   (little -> 0x3412 on this platform).
    static bool test_m32_read_r16_big_endian(void) {
        Zstr input = "\x12\x34";       // big-endian 0x1234
        Zstr start = input;
        u16  v     = 0;
    static bool test_m32_read_r16_big_endian(void) {
        Zstr input = "\x12\x34";       // big-endian 0x1234
        Zstr start = input;
        u16  v     = 0;
        StrReadFmt(input, "{>2r}", v); // advances `input` on success
    // code succeeds and yields the host-order interpretation of 0x12,0x34.
    static bool test_m32_read_r16_native_resolves(void) {
        Zstr input    = "\x12\x34";
        Zstr start    = input;
        u16  v        = 0;
    static bool test_m32_read_r16_native_resolves(void) {
        Zstr input    = "\x12\x34";
        Zstr start    = input;
        u16  v        = 0;
        u16  expected = IS_LITTLE_ENDIAN() ? (u16)0x3412 : (u16)0x1234;
    static bool test_m33_read_leading_plus(void) {
        i32  v = 0;
        Zstr z = "+5";
        StrReadFmt(z, "{}", v);
        return v == 5;
    
        f32  v = 7.5f;
        Zstr z = "1f";
        StrReadFmt(z, "{}", v);
        // Real rejects "1f" -> v stays 7.5. Mutant bypasses the gate.
    static bool test_m5_char_flag_reads_ordinal(void) {
        f32  v = 0.0f;
        Zstr z = "A";
        StrReadFmt(z, "{c}", v); // 'A' == 0x41 == 65
        return f32_close(v, 65.0f);
    static bool test_m5_invalid_char_breaks_scan(void) {
        f32  v = 0.0f;
        Zstr z = "12g3";
        StrReadFmt(z, "{}", v);
        return f32_close(v, 12.0f);
    
        Str  s = StrInit(&alloc);
        Zstr z = "\\x41BC"; // backslash, x, 4, 1, B, C  ->  'A', 'B', 'C'
        StrReadFmt(z, "{}", s);
    
        Str  s = StrInit(&alloc);
        Zstr z = "\\x41"; // -> 'A'
        StrReadFmt(z, "{}", s);
    
        Str  s = StrInit(&alloc);
        Zstr z = "\\x61";                             // -> 'a'
        StrReadFmt(z, "{A}", s);
        Str s = StrInit(&alloc);
        // "\x41BC" inside double quotes -> decoded "ABC"
        Zstr z = "\"\\x41BC\"";
        StrReadFmt(z, "{s}", s);
    
        Str  s = StrInit(&alloc);
        Zstr z = "\"\\x41\""; // quoted -> 'A'
        StrReadFmt(z, "{s}", s);
    
        Str  s = StrInit(&alloc);
        Zstr z = "\"\\x61\"";                         // quoted -> 'a'
        StrReadFmt(z, "{As}", s);
        bool             ok    = true;
    
        Zstr b = "\x12";
        StrAppendFmt(&out, "{c}", b);
        ok = ok && (ZstrCompare(StrBegin(&out), "\\x12") == 0);
        bool             ok    = true;
    
        Zstr b = "\x90";
        StrAppendFmt(&out, "{c}", b);
        ok = ok && (ZstrCompare(StrBegin(&out), "\\x90") == 0);
        bool             ok    = true;
    
        Zstr b = "\xab";
        StrAppendFmt(&out, "{c}", b);
        ok = ok && (ZstrCompare(StrBegin(&out), "\\xab") == 0);
        bool             ok    = true;
    
        Zstr b = "\xcd";
        StrAppendFmt(&out, "{c}", b);
        ok = ok && (ZstrCompare(StrBegin(&out), "\\xcd") == 0);
        bool             ok    = true;
    
        Zstr b = "\xab";
        StrAppendFmt(&out, "{A}", b);
        ok = ok && (ZstrCompare(StrBegin(&out), "\\xAB") == 0);
        bool             ok    = true;
    
        Zstr b = "\xcd";
        StrAppendFmt(&out, "{A}", b);
        ok = ok && (ZstrCompare(StrBegin(&out), "\\xCD") == 0);
        bool             ok    = true;
    
        Zstr lo_letter = "\x1b";
        StrAppendFmt(&out, "{c}", lo_letter);
        ok = ok && (ZstrCompare(StrBegin(&out), "\\x1b") == 0);
        StrClear(&out);
    
        Zstr hi_letter = "\xb1";
        StrAppendFmt(&out, "{c}", hi_letter);
        ok = ok && (ZstrCompare(StrBegin(&out), "\\xb1") == 0);
        bool ok = true;
        {
            Zstr     in = "2021-01-01T00:00:00Z";
            DateTime d  = {0};
            StrReadFmt(in, "{}", d);
        }
        {
            Zstr     in = "2021-01-01T05:30:00+05:30";
            DateTime d  = {0};
            StrReadFmt(in, "{}", d);
        }
        {
            Zstr     in = "2020-12-31T14:30:00-09:30";
            DateTime d  = {0};
            StrReadFmt(in, "{}", d);
        }
        {
            Zstr     in = "2021-01-01T00:00:00.123456789Z";
            DateTime d  = {0};
            StrReadFmt(in, "{}", d);
    static bool test_read_spec_too_long_rejected(void) {
        u64  v     = 0;
        Zstr p     = "ff";
        Zstr start = p;
        StrReadFmt(p, "{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}", v); // exactly 32 'x'
        u64  v     = 0;
        Zstr p     = "ff";
        Zstr start = p;
        StrReadFmt(p, "{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}", v); // exactly 32 'x'
        return (p == start) && (v == 0);
    static bool test_read_spec_len_32_boundary_rejected(void) {
        u64  v     = 999;
        Zstr p     = "5";
        Zstr start = p;
        StrReadFmt(p, "{11111111111111111111111111111111}", v); // valid 32-char width spec
        u64  v     = 999;
        Zstr p     = "5";
        Zstr start = p;
        StrReadFmt(p, "{11111111111111111111111111111111}", v); // valid 32-char width spec
        return (p == start) && (v == 999);
        DefaultAllocator a   = DefaultAllocatorInit();
        Str              out = StrInit(ALLOCATOR_OF(&a));
        Zstr             p   = "\\n\\n#rest";
        StrReadFmt(p, "{}#", out);
        bool ok = (StrLen(&out) == 2) && (StrBegin(&out)[0] == '\n') && (StrBegin(&out)[1] == '\n');
        u8 v = 0;
        {
            Zstr p = "0xff";
            StrReadFmt(p, "{}", v);
            if (v != 255)
        // Every bare prefix (no digits) must be rejected -- covers whichever
        // prefix-letter comparison the mutant flips.
        Zstr bare[] = {"0x", "0X", "0b", "0B", "0o", "0O"};
        for (u32 k = 0; k < sizeof(bare) / sizeof(bare[0]); ++k) {
            Zstr p     = bare[k];
        Zstr bare[] = {"0x", "0X", "0b", "0B", "0o", "0O"};
        for (u32 k = 0; k < sizeof(bare) / sizeof(bare[0]); ++k) {
            Zstr p     = bare[k];
            Zstr start = p;
            u8   w     = 7;
        for (u32 k = 0; k < sizeof(bare) / sizeof(bare[0]); ++k) {
            Zstr p     = bare[k];
            Zstr start = p;
            u8   w     = 7;
            StrReadFmt(p, "{}", w);
        // Quoted string of 50 chars: max_read_len (= rem_in) must allow the full
        // read; the `max_read_len = rem_in` survivor would cap it at 42.
        Zstr p = "\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\""; // 50 'a' quoted
        StrReadFmt(p, "{s}", out);
        bool ok = (StrLen(&out) == 50);
    // Read a Float and compare its canonical form. A wrong token boundary leaves
    // the pre-read sentinel.
    static bool read_float_is(Zstr in, Zstr expect) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *ab    = ALLOCATOR_OF(&alloc);
    static bool test_read_spec_scan(void) {
        i32  v   = 0;
        Zstr in  = "42";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(i32, &v));
        return out == in + 2 && v == 42;
        i32  v   = 0;
        Zstr in  = "42";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(i32, &v));
        return out == in + 2 && v == 42;
    }
        i32 v = 7;
        // 32 chars inside braces -> spec_len == 32 -> rejected.
        Zstr out = READ1("x", "{qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq}", TO_TYPE_SPECIFIC_IO(i32, &v));
        return out == NULL && v == 7;
    }
    static bool test_read_invalid_spec_leaves_dest(void) {
        i32  v   = 77;
        Zstr out = READ1("5", "{q}", TO_TYPE_SPECIFIC_IO(i32, &v));
        return out == NULL && v == 77;
    }
    static bool test_read_max_read_len_set(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Zstr             in    = "\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\""; // 50 A's quoted
        Str              s     = StrInit(&alloc);
        Zstr             out   = READ1(in, "{s}", TO_TYPE_SPECIFIC_IO(Str, &s));
        Zstr             in    = "\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\""; // 50 A's quoted
        Str              s     = StrInit(&alloc);
        Zstr             out   = READ1(in, "{s}", TO_TYPE_SPECIFIC_IO(Str, &s));
        bool             ok    = (out != NULL) && (StrLen(&s) == 50);
        StrDeinit(&s);
    static bool test_read_raw_u32_le(void) {
        u32  v   = 0;
        Zstr in  = "\xEF\xBE\xAD\xDE";
        Zstr out = READ1(in, "{<4r}", TO_TYPE_SPECIFIC_IO(u32, &v));
        return out == in + 4 && v == 0xDEADBEEFu;
        u32  v   = 0;
        Zstr in  = "\xEF\xBE\xAD\xDE";
        Zstr out = READ1(in, "{<4r}", TO_TYPE_SPECIFIC_IO(u32, &v));
        return out == in + 4 && v == 0xDEADBEEFu;
    }
    static bool test_read_raw_then_literal(void) {
        u8   v   = 0;
        Zstr in  = "\x05Z";
        Zstr out = READ1(in, "{<1r}Z", TO_TYPE_SPECIFIC_IO(u8, &v));
        return out == in + 2 && v == 0x05;
        u8   v   = 0;
        Zstr in  = "\x05Z";
        Zstr out = READ1(in, "{<1r}Z", TO_TYPE_SPECIFIC_IO(u8, &v));
        return out == in + 2 && v == 0x05;
    }
    static bool test_read_field_bounded_by_literal(void) {
        i32  v   = 0;
        Zstr in  = "12-end";
        Zstr out = READ1(in, "{}-end", TO_TYPE_SPECIFIC_IO(i32, &v));
        return out == in + 6 && v == 12;
        i32  v   = 0;
        Zstr in  = "12-end";
        Zstr out = READ1(in, "{}-end", TO_TYPE_SPECIFIC_IO(i32, &v));
        return out == in + 6 && v == 12;
    }
    static bool test_read_field_literal_with_escape(void) {
        i32  v   = 0;
        Zstr in  = "5!{y";
        Zstr out = READ1(in, "{}!{​{y", TO_TYPE_SPECIFIC_IO(i32, &v));
        return out == in + 4 && v == 5;
        i32  v   = 0;
        Zstr in  = "5!{y";
        Zstr out = READ1(in, "{}!{​{y", TO_TYPE_SPECIFIC_IO(i32, &v));
        return out == in + 4 && v == 5;
    }
    static bool test_vns_inf_len3(void) {
        f64  v = SENTINEL;
        Zstr z = "inf";
        StrReadFmt(z, "{}", v);
        return F64IsInf(v) && v > 0;
    static bool test_vns_inf_nan_cases(void) {
        f64  a = SENTINEL, b = SENTINEL, c = SENTINEL;
        Zstr za = "INF", zb = "nan", zc = "NaN";
        StrReadFmt(za, "{}", a);
        StrReadFmt(zb, "{}", b);
    static bool test_vns_neg_inf_len4(void) {
        f64  a = SENTINEL, b = SENTINEL;
        Zstr za = "-inf", zb = "-INF";
        StrReadFmt(za, "{}", a);
        StrReadFmt(zb, "{}", b);
    static bool test_vns_len4_not_neginf(void) {
        f64  v = SENTINEL;
        Zstr z = "1234";
        StrReadFmt(z, "{}", v);
        return f64_is(v, 1234.0);
    static bool test_vns_hex_slice_accepted(void) {
        f64  v = SENTINEL;
        Zstr z = "0x1f";
        StrReadFmt(z, "{}", v);
        // accepted -> StrToF64("0x1f") parses leading 0 -> 0.0.
    static bool test_vns_bin_slice_accepted(void) {
        f64  v = SENTINEL;
        Zstr z = "0b11";
        StrReadFmt(z, "{}", v);
        return f64_is(v, 0.0);
    static bool test_vns_oct_slice_accepted(void) {
        f64  v = SENTINEL;
        Zstr z = "0o7";
        StrReadFmt(z, "{}", v);
        return f64_is(v, 0.0);
    static bool test_vns_bin_digits(void) {
        f64  v = SENTINEL;
        Zstr z = "0b101";
        StrReadFmt(z, "{}", v);
        return f64_is(v, 0.0);
    static bool test_vns_oct_digits(void) {
        f64  v = SENTINEL;
        Zstr z = "0o17";
        StrReadFmt(z, "{}", v);
        return f64_is(v, 0.0);
    static bool test_vns_oct_boundary_digits(void) {
        f64  v = SENTINEL;
        Zstr z = "0o70";
        StrReadFmt(z, "{}", v);
        return f64_is(v, 0.0);
    static bool test_vns_exp_sign(void) {
        f64  v = SENTINEL;
        Zstr z = "1e+5";
        StrReadFmt(z, "{}", v);
        return f64_is(v, 100000.0);
    static bool test_vns_double_decimal_rejected(void) {
        f64  v = SENTINEL;
        Zstr z = "1.2.3";
        StrReadFmt(z, "{}", v);
        // The f64 scanner stops the token at the 2nd '.', so the slice is "1.2" and
    static bool test_vns_trailing_exp(void) {
        f64  v = SENTINEL;
        Zstr z = "12e";
        StrReadFmt(z, "{}", v);
        return f64_is(v, 12.0);
    static bool test_read_f64_char(void) {
        f64  v   = 0;
        Zstr in  = "ABCDEFGH";
        Zstr out = READ1(in, "{c}", TO_TYPE_SPECIFIC_IO(f64, &v));
        union {
        f64  v   = 0;
        Zstr in  = "ABCDEFGH";
        Zstr out = READ1(in, "{c}", TO_TYPE_SPECIFIC_IO(f64, &v));
        union {
            f64 f;
    static bool test_read_f64_exponent(void) {
        f64  v   = 0;
        Zstr in  = "1e5";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(f64, &v));
        return out == in + 3 && f64_is(v, 100000.0);
        f64  v   = 0;
        Zstr in  = "1e5";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(f64, &v));
        return out == in + 3 && f64_is(v, 100000.0);
    }
    static bool test_read_f64_neg_inf(void) {
        f64  v   = 0;
        Zstr in  = "-inf";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(f64, &v));
        return out == in + 4 && F64IsInf(v) && v < 0;
        f64  v   = 0;
        Zstr in  = "-inf";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(f64, &v));
        return out == in + 4 && F64IsInf(v) && v < 0;
    }
    static bool test_read_f64_double_dot(void) {
        f64  v   = 0;
        Zstr in  = "1.5.6";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(f64, &v));
        return out == in + 3 && f64_is(v, 1.5) && (*out == '.');
        f64  v   = 0;
        Zstr in  = "1.5.6";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(f64, &v));
        return out == in + 3 && f64_is(v, 1.5) && (*out == '.');
    }
    static bool test_read_u8(void) {
        u8   v   = 0;
        Zstr in  = "200";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(u8, &v));
        return out == in + 3 && v == 200;
        u8   v   = 0;
        Zstr in  = "200";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(u8, &v));
        return out == in + 3 && v == 200;
    }
    static bool test_blind_read_u8_hex(void) {
        u8   v   = 0;
        Zstr in  = "0xff";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(u8, &v));
        return out == in + 4 && v == 255;
        u8   v   = 0;
        Zstr in  = "0xff";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(u8, &v));
        return out == in + 4 && v == 255;
    }
    static bool test_read_u8_invalid_rejected(void) {
        u8   v   = 7;
        Zstr in  = "1f";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(u8, &v));
        // _read_u8 returns `start` (no advance) -> str_read_fmt sees next==in ->
        u8   v   = 7;
        Zstr in  = "1f";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(u8, &v));
        // _read_u8 returns `start` (no advance) -> str_read_fmt sees next==in ->
        // returns NULL; v untouched.
    static bool test_read_u8_bare_prefix(void) {
        u8   v   = 7;
        Zstr in  = "0x";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(u8, &v));
        return out == NULL && v == 7;
        u8   v   = 7;
        Zstr in  = "0x";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(u8, &v));
        return out == NULL && v == 7;
    }
        DebugAllocator dbg = DebugAllocatorInit();
        char          *s   = NULL;
        Zstr           in  = "hello world";
        Zstr           out = str_read_fmt(in, "{}", (TypeSpecificIO[]) {ZstrIO(s, &dbg.base)}, 1);
        // Unquoted, non-{s} read takes the whole input (whitespace only ends an
        char          *s   = NULL;
        Zstr           in  = "hello world";
        Zstr           out = str_read_fmt(in, "{}", (TypeSpecificIO[]) {ZstrIO(s, &dbg.base)}, 1);
        // Unquoted, non-{s} read takes the whole input (whitespace only ends an
        // is_string field), so s is the full "hello world".
        DebugAllocator dbg = DebugAllocatorInit();
        BitVec         bv  = BitVecInit(&dbg.base);
        Zstr           z   = "0x1";
        StrReadFmt(z, "{}", bv);
        bool ok = (BitVecToInteger(&bv) == 1) && (BitVecLen(&bv) == 4); // min-width clamp
        DefaultAllocator alloc = DefaultAllocatorInit();
        BitVec           bv    = BitVecInit(&alloc.base);
        Zstr             z     = "0xDEAD";
        StrReadFmt(z, "{}", bv);
        bool ok = (BitVecToInteger(&bv) == 0xDEAD) && (BitVecLen(&bv) == 16);
        DebugAllocator dbg = DebugAllocatorInit();
        BitVec         bv  = BitVecInit(&dbg.base);
        Zstr           z   = "0o1";
        StrReadFmt(z, "{}", bv);
        bool ok = (BitVecToInteger(&bv) == 1) && (BitVecLen(&bv) == 3);
        DebugAllocator dbg = DebugAllocatorInit();
        BitVec         bv  = BitVecInit(&dbg.base);
        Zstr           z   = "10110";
        StrReadFmt(z, "{}", bv);
        bool ok = (BitVecLen(&bv) == 5) && (BitVecToInteger(&bv) == 13);
        DebugAllocator dbg = DebugAllocatorInit();
        Int            v   = IntInit(&dbg.base);
        Zstr           z   = "12345";
        StrReadFmt(z, "{}", v);
        Str  t  = IntToStr(&v);
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int              v     = IntInit(&alloc.base);
        Zstr             z     = "+99";
        StrReadFmt(z, "{}", v);
        Str  t  = IntToStr(&v);
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int              v     = IntInit(&alloc.base);
        Zstr             z     = "ff";
        StrReadFmt(z, "{x}", v);
        Str  t  = IntToStr(&v);
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int              v     = IntFrom(777, &alloc.base);
        Zstr             z     = "12_3";
        Zstr             out   = str_read_fmt(z, "{}", (TypeSpecificIO[]) {TO_TYPE_SPECIFIC_IO(Int, &v)}, 1);
        // Real: '_' rejected -> returns start (==z) -> str_read_fmt sees next==in ->
        Int              v     = IntFrom(777, &alloc.base);
        Zstr             z     = "12_3";
        Zstr             out   = str_read_fmt(z, "{}", (TypeSpecificIO[]) {TO_TYPE_SPECIFIC_IO(Int, &v)}, 1);
        // Real: '_' rejected -> returns start (==z) -> str_read_fmt sees next==in ->
        // NULL; v unchanged (still 777).
        DebugAllocator dbg = DebugAllocatorInit();
        Float          f   = FloatInit(&dbg.base);
        Zstr           z   = "3.14159";
        StrReadFmt(z, "{}", f);
        Str  t  = FloatToStr(&f);
        Float          f   = FloatInit(&dbg.base);
        (void)FloatTryFromStr(&f, "42");
        Zstr z   = "xyz"; // no float token
        Zstr out = str_read_fmt(z, "{}", (TypeSpecificIO[]) {TO_TYPE_SPECIFIC_IO(Float, &f)}, 1);
        Str  t   = FloatToStr(&f);
        (void)FloatTryFromStr(&f, "42");
        Zstr z   = "xyz"; // no float token
        Zstr out = str_read_fmt(z, "{}", (TypeSpecificIO[]) {TO_TYPE_SPECIFIC_IO(Float, &f)}, 1);
        Str  t   = FloatToStr(&f);
        bool ok  = (out == NULL) && (ZstrCompare(StrBegin(&t), "42") == 0);
    static bool test_read_f32_decimal(void) {
        f32  v   = 0;
        Zstr in  = "2.5";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(f32, &v));
        return out == in + 3 && F64Abs((f64)v - 2.5) < 1e-4;
        f32  v   = 0;
        Zstr in  = "2.5";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(f32, &v));
        return out == in + 3 && F64Abs((f64)v - 2.5) < 1e-4;
    }
    static bool test_read_f32_neg_inf(void) {
        f32  v   = 0;
        Zstr in  = "-inf";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(f32, &v));
        return out == in + 4 && F64IsInf((f64)v) && v < 0;
        f32  v   = 0;
        Zstr in  = "-inf";
        Zstr out = READ1(in, "{}", TO_TYPE_SPECIFIC_IO(f32, &v));
        return out == in + 4 && F64IsInf((f64)v) && v < 0;
    }
    // 2408 / 2421 / 2466: quoted-string read whose budget saturates before the
    // closing quote -> unterminated-quote branch frees the destination Str.
    static bool leak_quoted_unterminated(Zstr input, Zstr fmt) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Str            s   = StrInit(ALLOCATOR_OF(&dbg));
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Str            s   = StrInit(ALLOCATOR_OF(&dbg));
        Zstr           p   = input;
        StrReadFmt(p, fmt, s); // reader frees s on the unterminated/error branch
        bool ok = (DebugAllocatorLiveCount(&dbg) == 0) && (DebugAllocatorLiveBytes(&dbg) == 0);
    // 3232 / 3273: BitVec hex/oct read overflow error path frees the internal
    // scratch (allocated through the destination BitVec's allocator).
    static bool leak_bitvec_overflow(Zstr input) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        BitVec         bv  = BitVecInit(ALLOCATOR_OF(&dbg));
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        BitVec         bv  = BitVecInit(ALLOCATOR_OF(&dbg));
        Zstr           p   = input;
        StrReadFmt(p, "{}", bv);
        BitVecDeinit(&bv);
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Str            s   = StrInit(ALLOCATOR_OF(&dbg));
        Zstr           p   = "aaaaaaaaaaaaaaaaaaaaaaaa\\q"; // 24 'a' + invalid \q
        StrReadFmt(p, "{}", s);
        bool ok = (DebugAllocatorLiveCount(&dbg) == 0) && (DebugAllocatorLiveBytes(&dbg) == 0);
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          fv  = FloatInit(ALLOCATOR_OF(&dbg));
        Zstr           p   = "1e99999999999999999999999999999999999999999999999999";
        StrReadFmt(p, "{}", fv);
        FloatDeinit(&fv);
        Int value = IntFromStr("123456789012345678901234567890", adbg);
    
        Zstr input = "42";
        Zstr start = input;
        StrReadFmt(input, "{}", value);
    
        Zstr input = "42";
        Zstr start = input;
        StrReadFmt(input, "{}", value);
        bool ok = (input != start); // pointer advanced => read succeeded
        Float value = FloatFromStr("987654321098765432109876543210.5", adbg);
    
        Zstr input = "2.5";
        Zstr start = input;
        StrReadFmt(input, "{}", value);
    
        Zstr input = "2.5";
        Zstr start = input;
        StrReadFmt(input, "{}", value);
        bool ok = (input != start); // pointer advanced => read succeeded
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Log.h>
    
        // Test StrFind (Str * key) with match at end
        Zstr found1 = StrFind(&haystack, &needle1);
        bool result = (found1 != NULL && ZstrCompare(found1, "World") == 0);
    
        // Test StrFind (Str * key) with match at beginning
        Zstr found2 = StrFind(&haystack, &needle2);
        result      = result && (found2 != NULL && ZstrCompare(found2, "Hello World") == 0);
    
        // Test StrFind (Str * key) with no match
        Zstr found3 = StrFind(&haystack, &needle3);
        result      = result && (found3 == NULL);
    
        // Test StrFind (Zstr key)
        Zstr found4 = StrFind(&haystack, "World");
        result      = result && (found4 != NULL && ZstrCompare(found4, "World") == 0);
    
        // Test StrFind (Cstr key, key_len)
        Zstr found5 = StrFind(&haystack, "Wor", 3);
        result      = result && (found5 != NULL && ZstrCompareN(found5, "World", 3) == 0);
    // key reports contained. An absent key via the Cstr/Zstr path must be false.
    static bool test_contains_cstr_absent_key_false(void) {
        WriteFmt("Testing StrContains(Zstr) absent key is false\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
    // it 42.
    static bool test_cmp_zstr_equal(void) {
        WriteFmt("Testing StrCmp (Zstr form) reports equality\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
        bool result = (StrCmp(&hello, "Hello") == 0);
        if (!result) {
            WriteFmt("    FAIL: Expected StrCmp(==0) for equal Zstr\n");
        }
        WriteFmt("Testing StrEndsWith(zstr) validates a NULL s (should abort)\n");
    
        (void)StrEndsWith((const Str *)NULL, "x"); // Zstr suffix -> str_ends_with_zstr
    
        return false;                              // unreachable on real code
    // (Str.Mutants7).
    static bool test_cmp_zstr_validates(void) {
        WriteFmt("Testing StrCmp (Zstr form) validates its Str (deadend)\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Log.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Allocator/Debug.h>
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Zstr test_str = "Hello, World!";
        size len      = 5; // Just "Hello"
        Str  s        = StrInitFromCstr(test_str, len, &alloc);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Zstr test_str = "Hello, World!";
        Str  s        = StrInitFromZstr(test_str, &alloc);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Zstr test_str = "Alias Test";
        Str  s        = StrZ(test_str, &alloc);
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Log.h>
    // Test StrInsertMany 3-arg Zstr form
    bool test_str_insert_zstr(void) {
        WriteFmt("Testing StrInsertMany (Zstr form)\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        // Insert a string in the middle
        Zstr w = " World";
        StrInsertMany(&s, w, 2);
    
        // Append formatted suffix.
        StrAppendFmt(&s, " {} {}", (Zstr) "World", (u32)2023);
    
        // Check that the string was appended correctly
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Log.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Log.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Allocator/Budget.h>
        // Test prefix handling
        struct {
            Zstr input;
            u64  expected;
            u8   base;
    
            // String should have expected decimal places
            Zstr dot_pos = ZstrFindChar(StrBegin(&s), '.');
            if (dot_pos) {
                size decimal_places = ZstrLen(dot_pos + 1);
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Log.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Map.h>
    #include <Misra/Std/Container/Str.h>
    
    static bool test_map_deep_copy_zstrs(void) {
        typedef Map(Zstr, Zstr) ZstrMap;
        DefaultAllocator alloc = DefaultAllocatorInit();
        ZstrMap          map   = MapInitWithDeepCopy(
        const char *value              = value_buf;
        const char *second_value       = second_value_buf;
        Zstr       *stored_value;
        int         value_count = 0;
    
    static bool test_map_policy_switch_preserves_entries(void) {
        typedef Map(Zstr, Zstr) ZstrMap;
        DefaultAllocator alloc = DefaultAllocatorInit();
        ZstrMap          map   = MapInitWithDeepCopy(
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Map.h>
    #include <Misra/Std/Container/Str.h>
    
    static bool test_map_init_deep_copy_typed(void) {
        typedef Map(Zstr, Zstr) ZstrMap;
        DefaultAllocator alloc = DefaultAllocatorInit();
        ZstrMap          map   = MapInitWithDeepCopyT(
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Map.h>
    #include <Misra/Std/Container/Str.h>
    
    static bool test_map_type_deep_copy_wiring(void) {
        typedef Map(Zstr, Zstr) ZstrMap;
        DefaultAllocator alloc = DefaultAllocatorInit();
        ZstrMap          map   = MapInitWithDeepCopy(
    #include <Misra/Std/Container/Map.h>
    #include <Misra/Std/Log.h>
    #include <Misra/Std/Zstr.h>
    #include "../../Util/TestRunner.h"
    // callbacks, the clones would leak and the live count would be non-zero.
    static bool test_map_deep_copy_deinit_on_remove(void) {
        typedef Map(Zstr, Zstr) ZstrMap;
        DebugAllocator dbg = DebugAllocatorInit();
        // Deep-copy callbacks for both key and value, plus a value comparator
        TestFunction *deadend_tests,
        int           deadend_count,
        Zstr          test_name
    ) {
        WriteFmt("[INFO] Starting {} tests\n\n", test_name ? test_name : "Test Suite");
    #define TEST_RUNNER_H
    
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
        TestFunction *deadend_tests,
        int           deadend_count,
        Zstr          test_name
    );
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Memory.h>
    #include <Misra/Sys.h>
    // borrowed (env-var lifetime) or a static literal -- caller must not
    // free.
    static Zstr tmp_dir_path(void) {
    #if PLATFORM_WINDOWS
        Zstr p = EnvGet("TEMP");
    static Zstr tmp_dir_path(void) {
    #if PLATFORM_WINDOWS
        Zstr p = EnvGet("TEMP");
        if (p && *p)
            return p;
        return "C:/Windows/Temp";
    #else
        Zstr p = EnvGet("TMPDIR");
        if (p && *p)
            return p;
    // Compose `<tmp_dir>/<name>` into `out`. Forward slash works on both
    // POSIX and Win32 (CRT + kernel APIs accept either separator).
    static void tmp_path_join(char *out, size out_size, Zstr name) {
        Zstr base    = tmp_dir_path();
        size baselen = 0;
    // POSIX and Win32 (CRT + kernel APIs accept either separator).
    static void tmp_path_join(char *out, size out_size, Zstr name) {
        Zstr base    = tmp_dir_path();
        size baselen = 0;
        while (base[baselen])
    static const u32 kAge = 7;
    
    static bool write_file(Zstr path, const u8 *data, u64 size) {
        // Use Misra's File API so this test runs under -nostdlib too
        // (no libc fopen/fwrite/fclose).
    static u8 pe_blob[PE_BLOB_SIZE];
    
    static void build_pe_blob(Zstr pdb_path) {
        MemSet(pe_blob, 0, sizeof(pe_blob));
    // corrupted so the (GUID, age) pairing check in the cache rejects the PDB
    // even though PdbOpen itself still succeeds.
    static void build_pdb_blob_va(Zstr func_name, u32 sec_va, u32 func_rva, bool match_guid) {
        MemSet(pdb_blob, 0, sizeof(pdb_blob));
    // Standard PDB: one function in a `.text` section based at RVA 0x1000,
    // GUID/age matching the PE built by `build_pe_blob`.
    static void build_pdb_blob(Zstr func_name, u32 func_rva) {
        build_pdb_blob_va(func_name, 0x1000, func_rva, true);
    }
    // `cv_path`: pass the on-disk `pdb_path` for the exact-path case, or a bogus
    // path whose basename equals the sidecar to exercise the basename fallback.
    static bool write_pe_pdb(Zstr pe_path, Zstr pdb_path, Zstr cv_path) {
        build_pe_blob(cv_path);
        build_pdb_blob("winproc", 0x1100);
        const u64 module_base = 0x140000000ull;
        const u64 ip          = module_base + 0x1100;
        Zstr      name        = NULL;
        u32       offset      = 0;
        bool      ok          = PdbCacheResolve(&cache, (Zstr)pe_path, module_base, ip, &name, &offset);
        Zstr      name        = NULL;
        u32       offset      = 0;
        bool      ok          = PdbCacheResolve(&cache, (Zstr)pe_path, module_base, ip, &name, &offset);
        ok                    = ok && name && ZstrCompare(name, "winproc") == 0 && offset == 0;
        name          = NULL;
        offset        = 0;
        ok            = ok && PdbCacheResolve(&cache, (Zstr)pe_path, module_base, ip2, &name, &offset);
        ok            = ok && name && ZstrCompare(name, "winproc") == 0 && offset == 0x10;
        DefaultAllocatorDeinit(&alloc);
    
        FileRemove((Zstr)pe_path);
        FileRemove((Zstr)pdb_path);
        return ok;
    
        FileRemove((Zstr)pe_path);
        FileRemove((Zstr)pdb_path);
        return ok;
    }
    
        PdbCache cache = PdbCacheInit(base);
        Zstr     name  = NULL;
        bool     ok    = !PdbCacheResolve(&cache, (Zstr)missing, 0, 0x1000, &name, NULL);
        PdbCacheDeinit(&cache);
        PdbCache cache = PdbCacheInit(base);
        Zstr     name  = NULL;
        bool     ok    = !PdbCacheResolve(&cache, (Zstr)missing, 0, 0x1000, &name, NULL);
        PdbCacheDeinit(&cache);
        DefaultAllocatorDeinit(&alloc);
    
        // Bare names (no separator), resolved relative to cwd.
        Zstr pe_name  = "misra_pdbcache_fb.exe";
        Zstr pdb_name = "misra_pdbcache_fb.pdb";
        // Bare names (no separator), resolved relative to cwd.
        Zstr pe_name  = "misra_pdbcache_fb.exe";
        Zstr pdb_name = "misra_pdbcache_fb.pdb";
    
        // CodeView points at a path that does NOT exist; its basename matches the
            PdbCache  cache = PdbCacheInit(base);
            const u64 mbase = 0x140000000ull;
            Zstr      name  = NULL;
            u32       off   = 0;
            ok              = PdbCacheResolve(&cache, pe_name, mbase, mbase + 0x1100, &name, &off);
        if (wrote) {
            PdbCache cache = PdbCacheInit(base);
            Zstr     name  = NULL;
            // PE opens, PDB lookup fails -> resolve returns false.
            ok = !PdbCacheResolve(&cache, (Zstr)pe_path, 0x140000000ull, 0x140001100ull, &name, NULL);
            Zstr     name  = NULL;
            // PE opens, PDB lookup fails -> resolve returns false.
            ok = !PdbCacheResolve(&cache, (Zstr)pe_path, 0x140000000ull, 0x140001100ull, &name, NULL);
            PdbCacheDeinit(&cache);
            // Teardown returns every allocation (the failed-lookup candidate too).
        }
    
        FileRemove((Zstr)pe_path);
        DebugAllocatorDeinit(&alloc);
        return ok;
        if (wrote) {
            PdbCache cache = PdbCacheInit(base);
            Zstr     name  = NULL;
            // PDB opens but GUID/age disagree -> resolve rejects it.
            ok = !PdbCacheResolve(&cache, (Zstr)pe_path, 0x140000000ull, 0x140001100ull, &name, NULL);
            Zstr     name  = NULL;
            // PDB opens but GUID/age disagree -> resolve rejects it.
            ok = !PdbCacheResolve(&cache, (Zstr)pe_path, 0x140000000ull, 0x140001100ull, &name, NULL);
            PdbCacheDeinit(&cache);
            // The briefly-opened, then-rejected PDB must be freed.
        }
    
        FileRemove((Zstr)pe_path);
        FileRemove((Zstr)pdb_path);
        DebugAllocatorDeinit(&alloc);
    
        FileRemove((Zstr)pe_path);
        FileRemove((Zstr)pdb_path);
        DebugAllocatorDeinit(&alloc);
        return ok;
            PdbCache  cache = PdbCacheInit(base);
            const u64 mbase = 0x140000000ull;
            Zstr      name  = NULL;
            u32       off   = 0;
            u32       off   = 0;
    
            bool ra = PdbCacheResolve(&cache, (Zstr)a_pe, mbase, mbase + 0x1100, &name, &off);
            bool rb = PdbCacheResolve(&cache, (Zstr)b_pe, mbase, mbase + 0x1100, &name, &off);
    
            bool ra = PdbCacheResolve(&cache, (Zstr)a_pe, mbase, mbase + 0x1100, &name, &off);
            bool rb = PdbCacheResolve(&cache, (Zstr)b_pe, mbase, mbase + 0x1100, &name, &off);
    
            // Both modules now open and cached; snapshot the live allocations.
    
            // Re-resolve B at a different IP: must hit B's existing slot.
            Zstr name2 = NULL;
            bool rb2   = PdbCacheResolve(&cache, (Zstr)b_pe, mbase, mbase + 0x1108, &name2, &off);
            size after = DebugAllocatorLiveCount(&alloc);
            // Re-resolve B at a different IP: must hit B's existing slot.
            Zstr name2 = NULL;
            bool rb2   = PdbCacheResolve(&cache, (Zstr)b_pe, mbase, mbase + 0x1108, &name2, &off);
            size after = DebugAllocatorLiveCount(&alloc);
        }
    
        FileRemove((Zstr)a_pe);
        FileRemove((Zstr)a_pdb);
        FileRemove((Zstr)b_pe);
    
        FileRemove((Zstr)a_pe);
        FileRemove((Zstr)a_pdb);
        FileRemove((Zstr)b_pe);
        FileRemove((Zstr)b_pdb);
        FileRemove((Zstr)a_pe);
        FileRemove((Zstr)a_pdb);
        FileRemove((Zstr)b_pe);
        FileRemove((Zstr)b_pdb);
        DebugAllocatorDeinit(&alloc);
        FileRemove((Zstr)a_pdb);
        FileRemove((Zstr)b_pe);
        FileRemove((Zstr)b_pdb);
        DebugAllocatorDeinit(&alloc);
        return ok;
            PdbCache  cache = PdbCacheInit(base);
            const u64 mbase = 0x140000000ull;
            Zstr      name  = NULL;
            u32       off   = 0;
            bool      r     = PdbCacheResolve(&cache, (Zstr)pe_path, mbase, mbase + 0x1100, &name, &off);
            Zstr      name  = NULL;
            u32       off   = 0;
            bool      r     = PdbCacheResolve(&cache, (Zstr)pe_path, mbase, mbase + 0x1100, &name, &off);
    
            // A populated cache with an opened PE+PDB sits strictly above baseline.
        }
    
        FileRemove((Zstr)pe_path);
        FileRemove((Zstr)pdb_path);
        DebugAllocatorDeinit(&alloc);
    
        FileRemove((Zstr)pe_path);
        FileRemove((Zstr)pdb_path);
        DebugAllocatorDeinit(&alloc);
        return ok;
            PdbCache  cache = PdbCacheInit(base);
            const u64 mbase = 0x140000000ull;
            Zstr      name  = NULL;
            u32       off   = 0;
            // ip exactly at module_base -> RVA 0 -> resolves under real `<`.
            u32       off   = 0;
            // ip exactly at module_base -> RVA 0 -> resolves under real `<`.
            ok = PdbCacheResolve(&cache, (Zstr)pe_path, mbase, mbase, &name, &off);
            ok = ok && name && ZstrCompare(name, "winzero") == 0 && off == 0;
            PdbCacheDeinit(&cache);
        }
    
        FileRemove((Zstr)pe_path);
        FileRemove((Zstr)pdb_path);
        DefaultAllocatorDeinit(&alloc);
    
        FileRemove((Zstr)pe_path);
        FileRemove((Zstr)pdb_path);
        DefaultAllocatorDeinit(&alloc);
        return ok;
            PdbCache  cache = PdbCacheInit(base);
            const u64 mbase = 0x140000000ull;
            Zstr      name  = NULL;
            u32       off   = 0;
            ok              = PdbCacheResolve(&cache, (Zstr)pe_path, mbase, mbase + 0xFFFFFFFFull, &name, &off);
            Zstr      name  = NULL;
            u32       off   = 0;
            ok              = PdbCacheResolve(&cache, (Zstr)pe_path, mbase, mbase + 0xFFFFFFFFull, &name, &off);
            ok              = ok && name && ZstrCompare(name, "winmax") == 0 && off == 0;
            PdbCacheDeinit(&cache);
        }
    
        FileRemove((Zstr)pe_path);
        FileRemove((Zstr)pdb_path);
        DefaultAllocatorDeinit(&alloc);
    
        FileRemove((Zstr)pe_path);
        FileRemove((Zstr)pdb_path);
        DefaultAllocatorDeinit(&alloc);
        return ok;
            const u64 mbase = 0x140000000ull;
            StrInitStack(mod, 1100) {
                StrPushBackMany(&mod, (Zstr)pe_path);
                Zstr name = NULL;
                u32  off  = 0;
            StrInitStack(mod, 1100) {
                StrPushBackMany(&mod, (Zstr)pe_path);
                Zstr name = NULL;
                u32  off  = 0;
                // ip strictly below module_base -> delegated resolve returns false.
        }
    
        FileRemove((Zstr)pe_path);
        FileRemove((Zstr)pdb_path);
        DefaultAllocatorDeinit(&alloc);
    
        FileRemove((Zstr)pe_path);
        FileRemove((Zstr)pdb_path);
        DefaultAllocatorDeinit(&alloc);
        return ok;
            PdbCache  cache = PdbCacheInit(base);
            const u64 mbase = 0x140000000ull;
            Zstr      name  = NULL;
            u32       off   = 0;
            ok              = PdbCacheResolve(&cache, (Zstr)pe_path, mbase, mbase + 0x1100, &name, &off);
            Zstr      name  = NULL;
            u32       off   = 0;
            ok              = PdbCacheResolve(&cache, (Zstr)pe_path, mbase, mbase + 0x1100, &name, &off);
            ok              = ok && name && ZstrCompare(name, "winproc") == 0 && off == 0;
            PdbCacheDeinit(&cache);
        }
    
        FileRemove((Zstr)pe_path);
        FileRemove((Zstr)pdb_path);
        DefaultAllocatorDeinit(&alloc);
    
        FileRemove((Zstr)pe_path);
        FileRemove((Zstr)pdb_path);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        if (wrote) {
            PdbCache cache = PdbCacheInit(a);
            Zstr     name  = NULL;
            ok             = !PdbCacheResolve(&cache, (Zstr)pe_path, 0x140000000ull, 0x140001100ull, &name, NULL);
            PdbCacheDeinit(&cache);
            PdbCache cache = PdbCacheInit(a);
            Zstr     name  = NULL;
            ok             = !PdbCacheResolve(&cache, (Zstr)pe_path, 0x140000000ull, 0x140001100ull, &name, NULL);
            PdbCacheDeinit(&cache);
            ok = ok && DebugAllocatorLiveCount(&alloc) == baseline;
        }
    
        FileRemove((Zstr)pe_path);
        FileRemove((Zstr)pdb_path);
        DebugAllocatorDeinit(&alloc);
    
        FileRemove((Zstr)pe_path);
        FileRemove((Zstr)pdb_path);
        DebugAllocatorDeinit(&alloc);
        return ok;
            PdbCache  cache = PdbCacheInit(base);
            const u64 mbase = 0x140000000ull;
            Zstr      na    = NULL;
            Zstr      nb    = NULL;
            u32       off   = 0;
            const u64 mbase = 0x140000000ull;
            Zstr      na    = NULL;
            Zstr      nb    = NULL;
            u32       off   = 0;
            bool      ra    = PdbCacheResolve(&cache, (Zstr)a_pe, mbase, mbase + 0x1100, &na, &off);
            Zstr      nb    = NULL;
            u32       off   = 0;
            bool      ra    = PdbCacheResolve(&cache, (Zstr)a_pe, mbase, mbase + 0x1100, &na, &off);
            bool      rb    = PdbCacheResolve(&cache, (Zstr)b_pe, mbase, mbase + 0x1100, &nb, &off);
            ok              = ra && rb && na && nb && ZstrCompare(na, "aproc") == 0 && ZstrCompare(nb, "bproc") == 0;
            u32       off   = 0;
            bool      ra    = PdbCacheResolve(&cache, (Zstr)a_pe, mbase, mbase + 0x1100, &na, &off);
            bool      rb    = PdbCacheResolve(&cache, (Zstr)b_pe, mbase, mbase + 0x1100, &nb, &off);
            ok              = ra && rb && na && nb && ZstrCompare(na, "aproc") == 0 && ZstrCompare(nb, "bproc") == 0;
            PdbCacheDeinit(&cache);
        }
    
        FileRemove((Zstr)a_pe);
        FileRemove((Zstr)a_pdb);
        FileRemove((Zstr)b_pe);
    
        FileRemove((Zstr)a_pe);
        FileRemove((Zstr)a_pdb);
        FileRemove((Zstr)b_pe);
        FileRemove((Zstr)b_pdb);
        FileRemove((Zstr)a_pe);
        FileRemove((Zstr)a_pdb);
        FileRemove((Zstr)b_pe);
        FileRemove((Zstr)b_pdb);
        DefaultAllocatorDeinit(&alloc);
        FileRemove((Zstr)a_pdb);
        FileRemove((Zstr)b_pe);
        FileRemove((Zstr)b_pdb);
        DefaultAllocatorDeinit(&alloc);
        return ok;
            PdbCache  cache = PdbCacheInit(base);
            const u64 mbase = 0x140000000ull;
            Zstr      name  = NULL;
            u32       off   = 0;
    
            // Two distinct modules -> two cache entries, each opening a PE+PDB.
            bool ra = PdbCacheResolve(&cache, (Zstr)a_pe, mbase, mbase + 0x1100, &name, &off);
            bool rb = PdbCacheResolve(&cache, (Zstr)b_pe, mbase, mbase + 0x1100, &name, &off);
            // Two distinct modules -> two cache entries, each opening a PE+PDB.
            bool ra = PdbCacheResolve(&cache, (Zstr)a_pe, mbase, mbase + 0x1100, &name, &off);
            bool rb = PdbCacheResolve(&cache, (Zstr)b_pe, mbase, mbase + 0x1100, &name, &off);
    
            // A populated two-entry cache sits strictly above baseline.
        }
    
        FileRemove((Zstr)a_pe);
        FileRemove((Zstr)a_pdb);
        FileRemove((Zstr)b_pe);
    
        FileRemove((Zstr)a_pe);
        FileRemove((Zstr)a_pdb);
        FileRemove((Zstr)b_pe);
        FileRemove((Zstr)b_pdb);
        FileRemove((Zstr)a_pe);
        FileRemove((Zstr)a_pdb);
        FileRemove((Zstr)b_pe);
        FileRemove((Zstr)b_pdb);
        DebugAllocatorDeinit(&alloc);
        FileRemove((Zstr)a_pdb);
        FileRemove((Zstr)b_pe);
        FileRemove((Zstr)b_pdb);
        DebugAllocatorDeinit(&alloc);
        return ok;
    
        PdbCache cache = PdbCacheInit(&bp);
        Zstr     name  = NULL;
        if (PdbCacheResolve(&cache, (char *)"/x", 0, 0x1000, &name, NULL))
            return false; // the entry must have failed to allocate
    #include <Misra.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Sys/Backtrace.h>
    #if FEATURE_SYS_SYMRESOLVE
    #include <Misra/Std/File.h>
    #include <Misra/Std/Log.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Sys/Dir.h>
    #include <Misra/Sys/Dns.h>
    }
    
    static void hosts_push_v4(DnsResolver *r, Zstr name, u8 b0, u8 b1, u8 b2, u8 b3) {
        HostsEntry e = {0};
        e.name       = StrInitFromCstr(name, ZstrLen(name), r->allocator);
    }
    
    static void hosts_push_v6(DnsResolver *r, Zstr name, const u8 ip16[16]) {
        HostsEntry e = {0};
        e.name       = StrInitFromCstr(name, ZstrLen(name), r->allocator);
    }
    
    static bool v4_is(const SocketAddr *ad, Allocator *a, Zstr expect) {
        if (ad->family != SOCKET_FAMILY_INET) {
            return false;
    }
    
    static bool v6_is(const SocketAddr *ad, Allocator *a, Zstr expect) {
        if (ad->family != SOCKET_FAMILY_INET6) {
            return false;
    // Write `body` to a fresh temp file in the cwd; returns its path (caller
    // FileRemove + StrDeinit). The on-disk file holds exactly `body`.
    static Str write_temp(Allocator *a, Zstr body) {
        Str  path = StrInit(a);
        File f    = file_open_temp(&path, a);
    }
    
    static const HostsEntry *find_host(HostsTable *t, Zstr name) {
        VecForeachPtr(t, e) {
            if (StrLen(&e->name) > 0 && ZstrCompare(StrBegin(&e->name), name) == 0) {
    
    // Compare nameserver `i` formatted as "ip:port" against `expect`.
    static bool ns_fmt_is(DnsResolver *r, u64 i, Allocator *a, Zstr expect) {
        if (VecLen(&r->nameservers) <= i) {
            return false;
            buf[k] = 'x';
        }
        Zstr tail = " spuriousname\n10.0.0.4 goodname\n";
        for (u64 i = 0; tail[i] != '\0'; ++i) {
            buf[k++] = tail[i];
        buf[k] = '\0';
    
        Str path = write_temp(a, (Zstr)buf);
        DnsResolverAddHostsPath(&r, &path);
    
        Str  body   = StrInit(a);
        Zstr pad    = "# padding line to push the fixture past the four kilobyte chunk\n";
        u64  padlen = ZstrLen(pad);
        for (int i = 0; i < 300; ++i) {
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Io.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Log.h>
    #include <Misra/Sys/Socket.h>
        Str        local_str = SocketAddrFormat(&local, a);
        SocketAddr connect_addr;
        bool       parsed = SocketAddrParse(&connect_addr, (Zstr)StrBegin(&local_str), SOCKET_KIND_TCP);
        StrDeinit(&local_str);
        if (!parsed) {
        }
    
        Zstr payload = "hello from socket test";
        size n       = (size)ZstrLen(payload);
        if (SocketSend(&client, payload, n) != (i64)n) {
        Str        local_str = SocketAddrFormat(&local, a);
        SocketAddr connect_addr;
        bool       parsed = SocketAddrParse(&connect_addr, (Zstr)StrBegin(&local_str), SOCKET_KIND_TCP);
        StrDeinit(&local_str);
        if (!parsed) {
        }
    
        Zstr payload = "X";
        bool sent    = SocketSend(&p.client, payload, 1) == 1;
    // Parse `spec`, format the result, compare against `expect` exactly.
    // Returns true iff the parse succeeded and the rendered string matches.
    static bool fmt_eq(Zstr spec, Zstr expect) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *a     = ALLOCATOR_OF(&alloc);
        ok    = ok && StrLen(&s) > 0;
        if (ok) {
            Zstr rendered = StrBegin(&s);
            ok            = ok && ZstrCompareN(rendered, "127.0.0.1:", 10u) == 0;
            // a real ephemeral port is non-zero: last char is not ":0\0"
        Str        local_str = SocketAddrFormat(&local, a);
        SocketAddr connect_addr;
        bool       parsed = SocketAddrParse(&connect_addr, (Zstr)StrBegin(&local_str), SOCKET_KIND_TCP);
        StrDeinit(&local_str);
        if (!parsed) {
        Str        local_str = SocketAddrFormat(&local, a);
        SocketAddr connect_addr;
        bool       parsed = SocketAddrParse(&connect_addr, (Zstr)StrBegin(&local_str), SOCKET_KIND_TCP);
        StrDeinit(&local_str);
        if (!parsed) {
        {
            Str  peer = SocketAddrFormat(&server.peer, a);
            Zstr p    = StrBegin(&peer);
            ok        = ok && StrLen(&peer) > 0 && p[0] == '1' && p[1] == '2' && p[2] == '7' && p[3] == '.';
            StrDeinit(&peer);
    
        // client -> server
        Zstr c2s = "client=>server:ABCDEFG";
        size n1  = (size)ZstrLen(c2s);
        ok       = ok && SocketSend(&client, c2s, n1) == (i64)n1;
        // server -> client (different payload + length so a swapped fd or a
        // length mutation surfaces here too)
        Zstr s2c = "server=>client:0123456789";
        size n2  = (size)ZstrLen(s2c);
        ok       = ok && SocketSend(&server, s2c, n2) == (i64)n2;
        ok = ok && ZstrCompare(StrBegin(&rendered), "127.0.0.1:0") != 0;
        // host portion must be exactly the loopback address.
        Zstr r = StrBegin(&rendered);
        ok     = ok && r[0] == '1' && r[1] == '2' && r[2] == '7' && r[3] == '.';
        StrDeinit(&rendered);
    
        // Now send data; poll(with a short timeout) must report READ ready.
        Zstr payload = "poke";
        size n       = (size)ZstrLen(payload);
        ok           = ok && SocketSend(&client, payload, n) == (i64)n;
        // Data is available, so the recv returns immediately with the bytes
        // -- never touching the timeout/error path.
        Zstr payload = "recv-timeout-set";
        size n       = (size)ZstrLen(payload);
        ok           = ok && SocketSend(&client, payload, n) == (i64)n;
        ok      = ok && SocketSetSendTimeoutMs(client.fd, 500);
    
        Zstr payload = "after-send-timeout";
        size n       = (size)ZstrLen(payload);
        ok           = ok && SocketSend(&client, payload, n) == (i64)n;
    
        // Connection still usable after toggling options.
        Zstr payload = "opts-ok";
        size n       = (size)ZstrLen(payload);
        ok           = ok && SocketSend(&client, payload, n) == (i64)n;
    
        Str spec = StrInit(a);
        StrAppendFmt(&spec, "{}", (Zstr) "1.2.3.4:4660");
    
        SocketAddr addr;
    
    // Parse `spec`, format the result, compare against `expect` exactly.
    static bool bl_fmt_eq(Zstr spec, Zstr expect) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *a     = ALLOCATOR_OF(&alloc);
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Memory.h>
    #include <Misra/Std/File.h>
    }
    
    static bool write_file(Zstr path, const u8 *data, u64 size) {
        File f = FileOpen(path, "wb");
        if (!FileIsOpen(&f))
    typedef struct SymSpec {
        u64  vmaddr;
        Zstr name;
    } SymSpec;
        u32 str_size = 1;
        for (u32 i = 0; i < nsyms; ++i) {
            Zstr s = syms[i].name;
            u32  n = 0;
            while (s[n])
            wr_u64(&n[8], syms[i].vmaddr);
    
            Zstr s    = syms[i].name;
            u32  nlen = 0;
            while (s[nlen])
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        Zstr    bin_path = "/tmp/misra_macho_main.bin";
        SymSpec sym      = {.vmaddr = 0x100000100ull, .name = "real_main_proc"};
        u64     bin_size = build_macho_image(bin_buf, kUuid, &sym, 1);
        const u64 slide      = 0x100;
        const u64 runtime_ip = 0x100000100ull + 0x10 + slide;
        Zstr      name       = NULL;
        u32       offset     = 0;
        bool      ok         = MachoCacheResolve(&cache, bin_path, slide, runtime_ip, &name, &offset);
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        Zstr bin_path  = "/tmp/misra_macho_stripped";
        Zstr dsym_dir  = "/tmp/misra_macho_stripped.dSYM/Contents/Resources/DWARF";
        Zstr dsym_path = "/tmp/misra_macho_stripped.dSYM/Contents/Resources/DWARF/misra_macho_stripped";
    
        Zstr bin_path  = "/tmp/misra_macho_stripped";
        Zstr dsym_dir  = "/tmp/misra_macho_stripped.dSYM/Contents/Resources/DWARF";
        Zstr dsym_path = "/tmp/misra_macho_stripped.dSYM/Contents/Resources/DWARF/misra_macho_stripped";
        Zstr bin_path  = "/tmp/misra_macho_stripped";
        Zstr dsym_dir  = "/tmp/misra_macho_stripped.dSYM/Contents/Resources/DWARF";
        Zstr dsym_path = "/tmp/misra_macho_stripped.dSYM/Contents/Resources/DWARF/misra_macho_stripped";
    
        // Make the dSYM bundle directory.
        const u64 slide      = 0;
        const u64 runtime_ip = 0x100000208ull; // 8 bytes into dsym_only_fn
        Zstr      name       = NULL;
        u32       offset     = 0;
        bool      ok         = MachoCacheResolve(&cache, bin_path, slide, runtime_ip, &name, &offset);
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        Zstr bin_path  = "/tmp/misra_macho_uuidmiss";
        Zstr dsym_path = "/tmp/misra_macho_uuidmiss.dSYM/Contents/Resources/DWARF/misra_macho_uuidmiss";
    
        Zstr bin_path  = "/tmp/misra_macho_uuidmiss";
        Zstr dsym_path = "/tmp/misra_macho_uuidmiss.dSYM/Contents/Resources/DWARF/misra_macho_uuidmiss";
    
        DirCreateAll("/tmp/misra_macho_uuidmiss.dSYM/Contents/Resources/DWARF");
        MachoCache cache = MachoCacheInit(base);
    
        Zstr name = NULL;
        bool ok   = !MachoCacheResolve(&cache, bin_path, 0, 0x100000208ull, &name, NULL);
    }
    
    static bool mc_write_file(Zstr path, const u8 *data, u64 size) {
        File f = FileOpen(path, "wb");
        if (!FileIsOpen(&f))
    typedef struct McSymSpec {
        u64  vmaddr;
        Zstr name;
    } McSymSpec;
        u32 str_size     = 1;
        for (u32 i = 0; i < nsyms; ++i) {
            Zstr s = syms[i].name;
            u32  n = 0;
            while (s[n])
            mc_wr_u16(&n[6], 0);
            mc_wr_u64(&n[8], syms[i].vmaddr);
            Zstr s    = syms[i].name;
            u32  nlen = 0;
            while (s[nlen])
    // payloads live after the load commands; the section records point at
    // their file offsets.
    static u64 mc_build_dwarf_dsym(u8 *out, const u8 uuid[16], u64 low, u64 high_off, Zstr fn_name) {
        MemSet(out, 0, MC_BLOB_CAP);
        Allocator     *base = ALLOCATOR_OF(&dbg);
    
        Zstr      bin_path = "/tmp/misra_mc_main.bin";
        McSymSpec sym      = {.vmaddr = 0x100000100ull, .name = "real_main_proc"};
        u64       bin_size = mc_build_macho_image(mc_bin_buf, mc_kUuid, &sym, 1);
    
        MachoCache cache      = MachoCacheInit(base);
        Zstr       name       = NULL;
        u32        offset     = 0;
        const u64  slide      = 0x100;
        Allocator     *base = ALLOCATOR_OF(&dbg);
    
        Zstr      bin_a = "/tmp/misra_mc_hit_a.bin";
        Zstr      bin_b = "/tmp/misra_mc_hit_b.bin";
        McSymSpec sym   = {.vmaddr = 0x100000100ull, .name = "fn_alpha"};
    
        Zstr      bin_a = "/tmp/misra_mc_hit_a.bin";
        Zstr      bin_b = "/tmp/misra_mc_hit_b.bin";
        McSymSpec sym   = {.vmaddr = 0x100000100ull, .name = "fn_alpha"};
        u64       sz_a  = mc_build_macho_image(mc_bin_buf, mc_kUuid, &sym, 1);
        MachoCache cache = MachoCacheInit(base);
    
        Zstr name = NULL;
        u32  off  = 0;
        Allocator     *base = ALLOCATOR_OF(&dbg);
    
        Zstr bin_path  = "/tmp/misra_mc_dsym";
        Zstr dsym_path = "/tmp/misra_mc_dsym.dSYM/Contents/Resources/DWARF/misra_mc_dsym";
        DirCreateAll("/tmp/misra_mc_dsym.dSYM/Contents/Resources/DWARF");
    
        Zstr bin_path  = "/tmp/misra_mc_dsym";
        Zstr dsym_path = "/tmp/misra_mc_dsym.dSYM/Contents/Resources/DWARF/misra_mc_dsym";
        DirCreateAll("/tmp/misra_mc_dsym.dSYM/Contents/Resources/DWARF");
    
        MachoCache cache    = MachoCacheInit(base);
        Zstr       name     = NULL;
        u32        offset   = 0;
        bool       resolved = MachoCacheResolve(&cache, bin_path, 0, 0x100000208ull, &name, &offset);
        Allocator     *base = ALLOCATOR_OF(&dbg);
    
        Zstr bin_path  = "/tmp/misra_mc_uuidmiss";
        Zstr dsym_path = "/tmp/misra_mc_uuidmiss.dSYM/Contents/Resources/DWARF/misra_mc_uuidmiss";
        DirCreateAll("/tmp/misra_mc_uuidmiss.dSYM/Contents/Resources/DWARF");
    
        Zstr bin_path  = "/tmp/misra_mc_uuidmiss";
        Zstr dsym_path = "/tmp/misra_mc_uuidmiss.dSYM/Contents/Resources/DWARF/misra_mc_uuidmiss";
        DirCreateAll("/tmp/misra_mc_uuidmiss.dSYM/Contents/Resources/DWARF");
    
        MachoCache cache = MachoCacheInit(base);
        Zstr       name  = NULL;
        // Resolve must fail: stripped main + UUID-mismatched dSYM.
        ok = ok && !MachoCacheResolve(&cache, bin_path, 0, 0x100000208ull, &name, NULL);
        Allocator     *base = ALLOCATOR_OF(&dbg);
    
        Zstr bin_path  = "/tmp/misra_mc_dwarf";
        Zstr dsym_path = "/tmp/misra_mc_dwarf.dSYM/Contents/Resources/DWARF/misra_mc_dwarf";
        DirCreateAll("/tmp/misra_mc_dwarf.dSYM/Contents/Resources/DWARF");
    
        Zstr bin_path  = "/tmp/misra_mc_dwarf";
        Zstr dsym_path = "/tmp/misra_mc_dwarf.dSYM/Contents/Resources/DWARF/misra_mc_dwarf";
        DirCreateAll("/tmp/misra_mc_dwarf.dSYM/Contents/Resources/DWARF");
        // bytes -- otherwise the info_n->42 value-substitution would be a
        // no-op against this exact fixture.
        Zstr      fn_name   = "dwarf_widget_function_with_long_name";
        const u64 low       = 0x100004000ull;
        const u64 high_off  = 0x80;
    
        MachoCache cache  = MachoCacheInit(base);
        Zstr       name   = NULL;
        u32        offset = 0;
        // file-relative VA low+0x20 -> 0x20 into the function.
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        Zstr bin_path = "/tmp/misra_mc_slide.bin";
        // Symbol at vmaddr 0: resolves a file-relative VA of 0.
        McSymSpec sym      = {.vmaddr = 0x0ull, .name = "fn_at_zero"};
    
        MachoCache cache = MachoCacheInit(base);
        Zstr       name  = NULL;
        u32        off   = 0;
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        Zstr      bin_path = "/tmp/misra_mc_str.bin";
        McSymSpec sym      = {.vmaddr = 0x100000100ull, .name = "str_fn"};
        u64       bin_size = mc_build_macho_image(mc_bin_buf, mc_kUuid, &sym, 1);
        StrPushBackMany(&mod, bin_path);
    
        Zstr name = NULL;
        u32  off  = 0;
        // Str overload -> macho_cache_resolve_str -> macho_cache_resolve_zstr.
    }
    
    static bool bl_write_file(Zstr path, const u8 *data, u64 size) {
        File f = FileOpen(path, "wb");
        if (!FileIsOpen(&f))
    // 42 (mutant 118) makes the parser read 30 bytes of __debug_str as
    // abbrev entries, corrupting the abbrev table.
    static u64 bl_build_dwarf_dsym(u8 *out, const u8 uuid[16], u64 low, u64 high_off, Zstr fn_name) {
        MemSet(out, 0, BL_BLOB_CAP);
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        Zstr bin_path  = "/tmp/misra_bl_dwarf";
        Zstr dsym_path = "/tmp/misra_bl_dwarf.dSYM/Contents/Resources/DWARF/misra_bl_dwarf";
        DirCreateAll("/tmp/misra_bl_dwarf.dSYM/Contents/Resources/DWARF");
    
        Zstr bin_path  = "/tmp/misra_bl_dwarf";
        Zstr dsym_path = "/tmp/misra_bl_dwarf.dSYM/Contents/Resources/DWARF/misra_bl_dwarf";
        DirCreateAll("/tmp/misra_bl_dwarf.dSYM/Contents/Resources/DWARF");
        DirCreateAll("/tmp/misra_bl_dwarf.dSYM/Contents/Resources/DWARF");
    
        Zstr      fn_name   = "dwarf_widget_function_with_long_name";
        const u64 low       = 0x100004000ull;
        const u64 high_off  = 0x80;
    
        MachoCache cache    = MachoCacheInit(base);
        Zstr       name     = NULL;
        u32        offset   = 0;
        bool       resolved = MachoCacheResolve(&cache, bin_path, 0, low + 0x20, &name, &offset);
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        Zstr bin_path  = "/tmp/misra_bl_dwarf2";
        Zstr dsym_path = "/tmp/misra_bl_dwarf2.dSYM/Contents/Resources/DWARF/misra_bl_dwarf2";
        DirCreateAll("/tmp/misra_bl_dwarf2.dSYM/Contents/Resources/DWARF");
    
        Zstr bin_path  = "/tmp/misra_bl_dwarf2";
        Zstr dsym_path = "/tmp/misra_bl_dwarf2.dSYM/Contents/Resources/DWARF/misra_bl_dwarf2";
        DirCreateAll("/tmp/misra_bl_dwarf2.dSYM/Contents/Resources/DWARF");
        DirCreateAll("/tmp/misra_bl_dwarf2.dSYM/Contents/Resources/DWARF");
    
        Zstr      fn_name   = "second_pass_dwarf_routine";
        const u64 low       = 0x100008000ull;
        const u64 high_off  = 0x40;
        MachoCache cache = MachoCacheInit(base);
    
        Zstr name1 = NULL;
        u32  off1  = 0;
        ok         = ok && MachoCacheResolve(&cache, bin_path, 0, low + 0x10, &name1, &off1);
        // Second resolve hits the cached entry: dsym already open, dwarf already
        // built. Same answer expected.
        Zstr name2 = NULL;
        u32  off2  = 0;
        ok         = ok && MachoCacheResolve(&cache, bin_path, 0, low + 0x30, &name2, &off2);
        Allocator     *base = ALLOCATOR_OF(&dbg);
    
        Zstr bin_path  = "/tmp/misra_bl_dwarf3";
        Zstr dsym_path = "/tmp/misra_bl_dwarf3.dSYM/Contents/Resources/DWARF/misra_bl_dwarf3";
        DirCreateAll("/tmp/misra_bl_dwarf3.dSYM/Contents/Resources/DWARF");
    
        Zstr bin_path  = "/tmp/misra_bl_dwarf3";
        Zstr dsym_path = "/tmp/misra_bl_dwarf3.dSYM/Contents/Resources/DWARF/misra_bl_dwarf3";
        DirCreateAll("/tmp/misra_bl_dwarf3.dSYM/Contents/Resources/DWARF");
        DirCreateAll("/tmp/misra_bl_dwarf3.dSYM/Contents/Resources/DWARF");
    
        Zstr      fn_name   = "dwarf_leakcheck_routine_name";
        const u64 low       = 0x10000c000ull;
        const u64 high_off  = 0x60;
    
        MachoCache cache    = MachoCacheInit(base);
        Zstr       name     = NULL;
        u32        offset   = 0;
        bool       resolved = MachoCacheResolve(&cache, bin_path, 0, low + 0x14, &name, &offset);
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Parsers/ProcMaps.h>
    #include <Misra/Sys/SymbolResolver.h>
    // Start address of an executable, file-backed mapping in a module OTHER than
    // `self_path`, via the public ProcMaps API only.
    static bool find_other_module_addr(Zstr self_path, u64 *out_addr) {
        DefaultAllocator a = DefaultAllocatorInit();
        ProcMaps         maps;
    #include <Misra.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Sys/SymbolResolver.h>
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Sys/SymbolResolver.h>
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Sys/SymbolResolver.h>
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Sys/SymbolResolver.h>
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Sys/SymbolResolver.h>
    #include <Misra.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Parsers/ProcMaps.h>
    #include <Misra/Sys/SymbolResolver.h>
    // back its runtime start and backing-file offset so a test can compute the
    // historical `start - file_offset` fallback base independently.
    static bool find_rw_mapping(Zstr path, u64 addr, u64 *map_start, u64 *map_file_offset) {
        DefaultAllocator a = DefaultAllocatorInit();
        ProcMaps         maps;
    #include <Misra.h>
    #include <Misra/Parsers/Pe.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra/Std/Allocator/Default.h>
    static const u8 kGuid[16] =
        {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99};
    static Zstr const kPdbPath = "C:\\build\\test.pdb";
    
    static void build_pe_blob(void) {
        }
        FileClose(&f);
        if (FileWriteAndClose((Zstr)StrBegin(&path), blob, sizeof(blob)) < 0) {
            FileRemove(&path);
            StrDeinit(&path);
    
        Pe   pe;
        bool ok = PeOpen(&pe, (Zstr)StrBegin(&path), base);
        if (ok) {
            ok = pe.machine == PE_MACHINE_X86_64 && VecLen(&pe.sections) == 1 &&
        }
        FileClose(&f);
        if (FileWriteAndClose((Zstr)StrBegin(&path), junk, sizeof(junk)) < 0) {
            FileRemove(&path);
            StrDeinit(&path);
    
        Pe   pe;
        bool opened = PeOpen(&pe, (Zstr)StrBegin(&path), base);
        if (opened)
            PeDeinit(&pe);
    #include <Misra/Parsers/Dns.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra.h>
    #include <Misra/Parsers/Pdb.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Allocator/Debug.h>
    // Write one S_PUB32 record at `*sym` and advance it. Returns nothing;
    // `*sym` points past the record on return.
    static void write_pub32(u8 **sym, u32 offset, u16 segment, Zstr name) {
        u32 namelen = (u32)ZstrLen(name) + 1; // include NUL
        u16 rec_len = (u16)(2 + 4 + 4 + 2 + namelen);
    // Write one S_PUB32 record at `*sym` and advance `*sym` past it.
    // `rec_kind` overridable so a non-PUB32 record can be injected.
    static void write_pub32_kind(u8 **sym, u16 rec_kind, u32 flags, u32 offset, u16 segment, Zstr name) {
        u32 namelen = (u32)ZstrLen(name) + 1; // include NUL
        u16 rec_len = (u16)(2 + 4 + 4 + 2 + namelen);
    
    // Write one IMAGE_SECTION_HEADER at `sec` (40 bytes).
    static void write_section(u8 *sec, Zstr name8, u32 vsize, u32 vaddr) {
        u8  nm[8] = {0, 0, 0, 0, 0, 0, 0, 0};
        u32 i;
        u32  offset;
        u16  segment;
        Zstr name;
    } PubSpec;
    }
    
    static u32 put_pub32(u8 *dst, u32 offset, u16 segment, Zstr name) {
        u32 namelen = (u32)ZstrLen(name) + 1;
        u16 rec_len = (u16)(2 + 4 + 4 + 2 + namelen);
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/File.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Parsers/ProcMaps.h>
    #include <Misra/Sys/Dir.h>
    // the loader's own success flag (true even when a line is malformed: a bad
    // line is skipped, not a hard failure).
    static bool pm_load_text(ProcMaps *m, Zstr text, DefaultAllocator *alloc) {
        return ProcMapsLoadFrom(m, text, ZstrLen(text), alloc);
    }
        // 200 * 26 bytes = 5200 bytes of filler, comfortably past one 4096 chunk,
        // before the distinctive trailing entry lands.
        Zstr filler   = "1000-1001 ---p 0 0:0 0 /f\n";
        bool wrote_ok = true;
        for (int i = 0; i < 200 && wrote_ok; ++i) {
            wrote_ok = (w == (i64)ZstrLen(filler));
        }
        Zstr late = "deadbeef000-deadbeef100 r-xp 0 0:0 0 /late\n";
        if (wrote_ok) {
            i64 w    = FileWrite(&f, late, (u64)ZstrLen(late));
    #include <Misra/Parsers/Http.h>
    #include <Misra/Std/File.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Allocator/Debug.h>
    #include <Misra/Std/Allocator/Default.h>
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Zstr raw =
            "GET /index.html HTTP/1.1\r\n"
            "Host: example.com\r\n"
    
        HttpRequest req  = HttpRequestInit(alloc_base);
        Zstr        next = HttpRequestParse(&req, raw);
    
        bool ok = (next != raw) && (req.method == HTTP_REQUEST_METHOD_GET) && (StrLen(&req.url) == 11) &&
    
        struct {
            Zstr              raw;
            HttpRequestMethod method;
        } cases[] = {
        for (u64 i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {
            HttpRequest req  = HttpRequestInit(alloc_base);
            Zstr        next = HttpRequestParse(&req, cases[i].raw);
            ok               = ok && (next != cases[i].raw) && (req.method == cases[i].method);
            HttpRequestDeinit(&req);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Zstr cases[] = {
            "GETX / HTTP/1.1\r\n\r\n",
            "PUTT / HTTP/1.1\r\n\r\n",
        for (u64 i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {
            HttpRequest req  = HttpRequestInit(alloc_base);
            Zstr        next = HttpRequestParse(&req, cases[i]);
            ok               = ok && (next == cases[i]) && (req.method == HTTP_REQUEST_METHOD_UNKNOWN);
            HttpRequestDeinit(&req);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Zstr cases[] = {
            "GE / HTTP/1.1\r\n\r\n",
            "POSTX / HTTP/1.1\r\n\r\n",
        for (u64 i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {
            HttpRequest req  = HttpRequestInit(alloc_base);
            Zstr        next = HttpRequestParse(&req, cases[i]);
            ok               = ok && (next == cases[i]) && (req.method == HTTP_REQUEST_METHOD_UNKNOWN);
            HttpRequestDeinit(&req);
    
        HttpRequest req  = HttpRequestInit(alloc_base);
        Zstr        in   = StrBegin(&raw);
        Zstr        next = HttpRequestParse(&req, in);
        HttpRequest req  = HttpRequestInit(alloc_base);
        Zstr        in   = StrBegin(&raw);
        Zstr        next = HttpRequestParse(&req, in);
    
        // Real code rejects: cursor returned unchanged (== in).
    
        HttpRequest req  = HttpRequestInit(alloc_base);
        Zstr        in   = StrBegin(&raw);
        Zstr        next = HttpRequestParse(&req, in);
        HttpRequest req  = HttpRequestInit(alloc_base);
        Zstr        in   = StrBegin(&raw);
        Zstr        next = HttpRequestParse(&req, in);
    
        bool ok = (next != in) && (VecLen(&req.headers) == 100);
        bool ok   = FileIsOpen(&f);
    
        Zstr payload = "hello-body";
        ok           = ok && (FileWrite(&f, payload, ZstrLen(payload)) == (i64)ZstrLen(payload));
        FileClose(&f);
    
        // A long URL forces the url Str onto the heap.
        Zstr raw =
            "GET /a-deliberately-long-url-path-to-force-heap-allocation HTTP/1.1\r\n"
            "\r\n";
    
        HttpRequest req  = HttpRequestInit(adbg);
        Zstr        next = HttpRequestParse(&req, raw);
        bool        ok   = (next != raw) && (StrLen(&req.url) > 0);
        ok               = ok && (DebugAllocatorLiveCount(&dbg) > 0);
        File f       = FileOpenTemp(&path, adbg);
        bool ok      = FileIsOpen(&f);
        Zstr payload = "file-payload-long-enough-to-heap-allocate-body";
        ok           = ok && (FileWrite(&f, payload, ZstrLen(payload)) == (i64)ZstrLen(payload));
        FileClose(&f);
    #include <Misra/Std/File.h>
    #include <Misra/Std/Memory.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Sys/Dir.h>
        // `_NSGetExecutablePath` wants `char *`; everything past this
        // point reads it through the project's `Zstr` (const char *).
        Zstr path = path_buf;
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        if (_NSGetExecutablePath(path_buf, &pathsize) != 0)
            return false;
        Zstr path = path_buf;
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    #include <Misra.h>
    #include <Misra/Parsers/Dwarf.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Parsers/Elf.h>
    #include <Misra/Std/Allocator/Default.h>
    }
    
    static Zstr stripped_path_arg = NULL;
    
    // Open the stripped sibling and try to resolve `func_addr` (a runtime
    // address is the same in both copies because objcopy -R only removes
    // non-allocated sections.
    static bool resolve_through_stripped(void (*func)(void), Zstr expect_name) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    #include <Misra.h>
    #include <Misra/Parsers/Dwarf.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Parsers/Elf.h>
    #include <Misra/Std/Allocator/Debug.h>
    // the total length. `version` and `length_override` allow malformed /
    // unsupported variants.
    static u64 build_debug_info(u8 *buf, u16 version, u32 length_override, u64 low, u64 high_off, Zstr name) {
        // CU body after unit_length: version(2) abbrev_off(4) addr_size(1)
        //   + DIE: abbrev_code(1) name(NUL-terminated) low_pc(8) high_pc(8)
    
    // Helper function to compare JSON output (removes spaces for comparison)
    bool compare_json_output(const Str *output, Zstr expected, DefaultAllocator *alloc) {
        // Create a copy of expected without spaces for comparison
        Str expected_str   = StrInitFromZstr(expected, alloc);
        );
    
        Zstr expected = "{}";
        if (!compare_json_output(&json, expected, &alloc)) {
            success = false;
        });
    
        Zstr expected = "{\"numbers\":[],\"strings\":[]}";
        if (!compare_json_output(&json, expected, &alloc)) {
            success = false;
        });
    
        Zstr expected = "{\"name\":\"\",\"description\":\"\"}";
        if (!compare_json_output(&json, expected, &alloc)) {
            success = false;
        });
    
        Zstr expected = "{\"temp\":-25,\"balance\":-1000.500000,\"delta\":-0.001000}";
        if (!compare_json_output(&json, expected, &alloc)) {
            success = false;
        });
    
        Zstr expected = "{\"int_zero\":0,\"float_zero\":0.000000,\"bool_false\":false}";
        if (!compare_json_output(&json, expected, &alloc)) {
            success = false;
        });
    
        Zstr expected = "{\"outer\":{},\"list\":[],\"deep\":{\"inner\":{}}}";
        if (!compare_json_output(&json, expected, &alloc)) {
            success = false;
        });
    
        Zstr expected = "{\"empty_obj\":{},\"filled_obj\":{\"x\":1},\"empty_arr\":[],\"filled_arr\":[1,2]}";
        if (!compare_json_output(&json, expected, &alloc)) {
            success = false;
        });
    
        Zstr expected = "{\"max_int\":2147483647,\"min_int\":-2147483648,\"one\":1,\"minus_one\":-1}";
        if (!compare_json_output(&json, expected, &alloc)) {
            success = false;
        JW_OBJ(json4, { JW_FLT_KV(json4, "pi", single_float); });
    
        Zstr expected1 = "{\"value\":42}";
        Zstr expected2 = "{\"text\":\"hello\"}";
        Zstr expected3 = "{\"flag\":true}";
    
        Zstr expected1 = "{\"value\":42}";
        Zstr expected2 = "{\"text\":\"hello\"}";
        Zstr expected3 = "{\"flag\":true}";
        Zstr expected4 = "{\"pi\":3.140000}";
        Zstr expected1 = "{\"value\":42}";
        Zstr expected2 = "{\"text\":\"hello\"}";
        Zstr expected3 = "{\"flag\":true}";
        Zstr expected4 = "{\"pi\":3.140000}";
        Zstr expected2 = "{\"text\":\"hello\"}";
        Zstr expected3 = "{\"flag\":true}";
        Zstr expected4 = "{\"pi\":3.140000}";
    
        if (!compare_json_output(&json1, expected1, &alloc))
    
    // Helper function to compare JSON output (removes whitespace for comparison)
    bool compare_json_output(const Str *output, Zstr expected, DefaultAllocator *alloc) {
        Str expected_str   = StrInitFromZstr(expected, alloc);
        Str output_clean   = StrInit(alloc);
        });
    
        Zstr expected = "{\"user\":{\"id\":123,\"profile\":{\"name\":\"Alice\",\"age\":30}},\"status\":\"active\"}";
        if (!compare_json_output(&json, expected, &alloc)) {
            success = false;
        });
    
        Zstr expected =
            "{\"company\":{\"departments\":{\"engineering\":{\"head\":\"John\",\"count\":25,\"budget\":150000.000000}},"
            "\"name\":\"TechCorp\"}}";
        });
    
        Zstr expected =
            "{\"status\":true,\"message\":\"Success\",\"data\":{\"12345\":{\"67890\":{\"distance\":0.850000,\"nearest_"
            "neighbor_analysis_id\":999,\"nearest_neighbor_binary_id\":888,\"nearest_neighbor_analysis_name\":\"test_"
        });
    
        Zstr expected =
            "{\"functions\":[{\"id\":12345,\"name\":\"test_func\",\"size\":1024,\"vaddr\":4096},{\"id\":54321,\"name\":"
            "\"helper_func\",\"size\":512,\"vaddr\":8192}]}";
        });
    
        Zstr expected =
            "{\"binary_id\":888,\"binary_name\":\"test_binary\",\"analysis_id\":999,\"sha256\":\"abc123\",\"tags\":["
            "\"malware\",\"x86\"],\"created_at\":\"2024-04-01\",\"model_id\":12345,\"model_name\":\"test_model\",\"owned_"
    });
    
    Zstr expected =
        "{\"functions\":{\"111\":{\"222\":{\"distance\":0.900000,\"name\":\"func1\"}},\"333\":{\"444\":{\"distance\":0."
        "800000,\"name\":\"func2\"}}}}";
        });
    
        Zstr expected =
            "{\"level1\":{\"level2\":{\"level3\":{\"message\":\"deep\",\"value\":42},\"flag\":true},\"name\":\"test\"}}";
        if (!compare_json_output(&json, expected, &alloc)) {
        });
    
        Zstr expected = "{\"numbers\":[1,2,3],\"strings\":[\"a\",\"b\",\"c\"],\"booleans\":[true,false,true]}";
        if (!compare_json_output(&json, expected, &alloc)) {
            success = false;
    
    // Helper function to compare expected JSON strings (removes spaces for comparison)
    bool compare_json_output(const Str *output, Zstr expected, DefaultAllocator *alloc) {
        // Create a copy of expected without spaces for comparison
        Str expected_str   = StrInitFromZstr(expected, alloc);
        });
    
        Zstr expected = "{\"name\":\"Alice\",\"city\":\"New York\"}";
        if (!compare_json_output(&json, expected, &alloc)) {
            success = false;
        });
    
        Zstr expected = "{\"count\":42,\"score\":95.500000,\"year\":2024}";
        if (!compare_json_output(&json, expected, &alloc)) {
            success = false;
        });
    
        Zstr expected = "{\"enabled\":true,\"visible\":false}";
        if (!compare_json_output(&json, expected, &alloc)) {
            success = false;
        });
    
        Zstr expected = "{\"id\":1001,\"name\":\"Bob\",\"age\":25,\"is_active\":true,\"salary\":50000.000000}";
        if (!compare_json_output(&json, expected, &alloc)) {
            success = false;
        });
    
        Zstr expected = "{\"debug_mode\":false,\"timeout\":30,\"log_level\":\"INFO\"}";
        if (!compare_json_output(&json, expected, &alloc)) {
            success = false;
        JW_OBJ(json, { JW_ARR_KV(json, "languages", languages, lang, { JW_STR(json, lang); }); });
    
        Zstr expected = "{\"languages\":[\"C\",\"Python\",\"Rust\"]}";
        if (!compare_json_output(&json, expected, &alloc)) {
            success = false;
        });
    
        Zstr expected = "{\"user\":{\"name\":\"Charlie\",\"email\":\"charlie@example.com\"},\"active\":true}";
        if (!compare_json_output(&json, expected, &alloc)) {
            success = false;
        });
    
        Zstr expected =
            "{\"id\":12345,\"name\":\"Laptop\",\"price\":999.990000,\"tags\":[\"electronics\",\"computers\",\"portable\"]}";
        if (!compare_json_output(&json, expected, &alloc)) {
        // message: "Hello, \"World\"!"       -> Hello, "World"!
        // data:    "line1\nline2\ttab"       -> line1<LF>line2<HT>tab
        Zstr path_want = "C:\\Program Files\\App";
        Zstr msg_want  = "Hello, \"World\"!";
        Zstr data_want = "line1\nline2\ttab";
        // data:    "line1\nline2\ttab"       -> line1<LF>line2<HT>tab
        Zstr path_want = "C:\\Program Files\\App";
        Zstr msg_want  = "Hello, \"World\"!";
        Zstr data_want = "line1\nline2\ttab";
        if (StrLen(&obj.path) != ZstrLen(path_want) || MemCompare(StrBegin(&obj.path), path_want, StrLen(&obj.path)) != 0) {
        Zstr path_want = "C:\\Program Files\\App";
        Zstr msg_want  = "Hello, \"World\"!";
        Zstr data_want = "line1\nline2\ttab";
        if (StrLen(&obj.path) != ZstrLen(path_want) || MemCompare(StrBegin(&obj.path), path_want, StrLen(&obj.path)) != 0) {
            WriteFmtLn("[DEBUG] Special characters FAILED: path content wrong");
            const Str *got;
            char       want;
            Zstr       name;
        } expect[] = {
            {    &obj.quote,  '"',     "quote"},
    
        // "\u" with no following hex digits, then closing quote/EOF.
        Zstr cases[] = {"\"\\u\"", "\"\\u12\"", "\"ab\\u\""};
        for (u64 i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {
            Str     j   = StrInitFromZstr(cases[i], &alloc);
    
        // missing ':' separator, missing closing brace, missing comma.
        Zstr cases[] = {
            "{\"a\" 1}",        // no colon
            "{\"a\":1",         // truncated, no closing brace
    // Helper: parse `src` into a fresh cfg, look up `key`, and compare the
    // stored value byte-for-byte against `expect`. Returns true on match.
    static bool kv_value_equals(Zstr src, Zstr key, Zstr expect) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        KvConfig         cfg   = KvConfigInit(&alloc);
        (void)KvConfigParse(input, &cfg);
    
        Zstr trues[]  = {"t1", "t2", "t3", "t4"};
        Zstr falses[] = {"f1", "f2", "f3", "f4"};
        for (u64 i = 0; i < 4; i++) {
    
        Zstr trues[]  = {"t1", "t2", "t3", "t4"};
        Zstr falses[] = {"f1", "f2", "f3", "f4"};
        for (u64 i = 0; i < 4; i++) {
            v      = false;
    // KvConfigParse branch where that Str actually holds a heap buffer leaks
    // it, leaving DebugAllocatorLiveCount > 0.
    static bool kv_parse_is_leak_free(Zstr src) {
        DebugAllocator dbg  = kv_lean_debug_allocator();
        Allocator     *base = ALLOCATOR_OF(&dbg);
Last updated on