Skip to content

ZstrToI64

Description

Parse a signed decimal integer from a null-terminated string. Skips ASCII whitespace, accepts an optional leading sign, then consumes the longest run of 0..9. Drops the libc strtoll / strtol dependency for callers that only need base-10.

Parameters

Name Direction Description
s in Source string.
endptr out If non-NULL, set to the first byte past the last digit consumed (or to s if no digits were found).

Success

Returns the parsed value as i64. Overflow wraps in the unsigned accumulator before sign application; callers that care should validate the value externally.

Failure

Returns 0 when no digits are present.

Usage example (Cross-references)

Usage examples (Cross-references)
        }
    
        parsed = ZstrToI64(value->data, &endptr);
    
        if (!endptr || endptr == value->data || *endptr != '\0') {
            num->f = ZstrToF64(ns.data, &end);
        } else {
            num->i = ZstrToI64(ns.data, &end);
        }
        if (end == ns.data) {
    }
    
    i64 ZstrToI64(const char *s, char **endptr) {
        if (!s) {
            if (endptr)
                }
    
                parsed = ZstrToI64(text + pos, &endptr);
                if (endptr == text + pos || *endptr != '\0') {
                    LOG_ERROR("Invalid Float exponent");
Last updated on