unlocalized.c

Include dependency graph for unlocalized.c:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "5" [label="term_typedef.h" tooltip="term_typedef.h"] "1" [label="/__w/AtomVM/AtomVM/src/libAtomVM/unlocalized.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/unlocalized.c" fillcolor="#BFBFBF"] "2" [label="unlocalized.h" tooltip="unlocalized.h"] "17" [label="utils.h" tooltip="utils.h"] "6" [label="assert.h" tooltip="assert.h"] "10" [label="errno.h" tooltip="errno.h"] "8" [label="inttypes.h" tooltip="inttypes.h"] "7" [label="limits.h" tooltip="limits.h"] "11" [label="locale.h" tooltip="locale.h"] "12" [label="math.h" tooltip="math.h"] "13" [label="stdarg.h" tooltip="stdarg.h"] "3" [label="stdbool.h" tooltip="stdbool.h"] "4" [label="stddef.h" tooltip="stddef.h"] "9" [label="stdint.h" tooltip="stdint.h"] "14" [label="stdio.h" tooltip="stdio.h"] "15" [label="stdlib.h" tooltip="stdlib.h"] "16" [label="string.h" tooltip="string.h"] "5" -> "6" [dir=forward tooltip="include"] "5" -> "7" [dir=forward tooltip="include"] "5" -> "8" [dir=forward tooltip="include"] "5" -> "9" [dir=forward tooltip="include"] "1" -> "2" [dir=forward tooltip="include"] "1" -> "10" [dir=forward tooltip="include"] "1" -> "7" [dir=forward tooltip="include"] "1" -> "11" [dir=forward tooltip="include"] "1" -> "12" [dir=forward tooltip="include"] "1" -> "13" [dir=forward tooltip="include"] "1" -> "14" [dir=forward tooltip="include"] "1" -> "15" [dir=forward tooltip="include"] "1" -> "16" [dir=forward tooltip="include"] "1" -> "17" [dir=forward tooltip="include"] "2" -> "3" [dir=forward tooltip="include"] "2" -> "4" [dir=forward tooltip="include"] "2" -> "5" [dir=forward tooltip="include"] "17" -> "8" [dir=forward tooltip="include"] "17" -> "3" [dir=forward tooltip="include"] "17" -> "4" [dir=forward tooltip="include"] "17" -> "14" [dir=forward tooltip="include"] "17" -> "15" [dir=forward tooltip="include"] }

Defines

PARSE_FLOAT_BUF_SIZE 256
UNLOCALIZED_STRATEGY 3

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)