unlocalized.c
Include dependency graph for unlocalized.c:
Functions
-
static void fix_decimal_separator(char *buf)
-
static int vsnprintf_c(char *buf, size_t size, const char *fmt, va_list ap)
-
int unlocalized_snprintf(char *buf, size_t size, const char *fmt, ...)
Locale-independent snprintf.
Behaves like snprintf but always uses ‘.’ as decimal separator regardless of LC_NUMERIC for floating-point conversions.
-
static size_t prepare_locale_retry_buf(const char *buf, char *retry_buf, size_t retry_buf_size, size_t *out_sep_len)
-
static double strtod_c(const char *buf, char **endp)
-
bool unlocalized_validate_bare_float_format(const char buf[], size_t len)
Validate strict bare decimal float format.
Checks that buf[0..len-1] matches the grammar: [+|-] DIGITS “.” DIGITS [(“e”|”E”) [+|-] DIGITS] where DIGITS is one or more ‘0’-‘9’ characters.
Rejects hex floats, inf, nan, whitespace, commas, and any other characters not in the grammar.
- Parameters:
buf – pointer to the character data (need not be null-terminated)
len – number of characters to validate
- Returns:
true if the format is valid, false otherwise
-
int unlocalized_strtod(const char buf[], size_t len, double *result)
Parse a double from a string locale-independently with strict validation.
Validates the input against the bare float format (see unlocalized_validate_bare_float_format), then parses with strtod using ‘.’ as decimal separator regardless of LC_NUMERIC. Rejects overflow (inf) but allows underflow (returns 0.0).
- Parameters:
buf – pointer to the character data (need not be null-terminated)
len – number of characters to parse (max 255)
result – [out] on success, the parsed double value
- Returns:
0 on success, -1 on error (caller should raise badarg)