Skip to content

cli_utils.h

Source: samples/common/core/cli_utils.h

C utility functions for CLI flag parsing.


Functions

parse_int_or_default

static int parse_int_or_default(const char *text, int dflt)

Parse a decimal integer from a string, returning a default on failure.

Parameters:

Name Type Description
text const char * Null-terminated string to parse (may be NULL).
dflt int Value returned when text is NULL or not a valid integer.

Returns: Parsed integer, or dflt.

parse_u64_hex_or_default

static uint64_t parse_u64_hex_or_default(const char *text, uint64_t dflt)

Parse a uint64 from a string (auto-detecting hex via 0x prefix).

Parameters:

Name Type Description
text const char * Null-terminated string to parse (may be NULL).
dflt uint64_t Value returned when text is NULL or not a valid integer.

Returns: Parsed value, or dflt.

get_flag_value

static const char * get_flag_value(const char *arg, const char *key)

Extract the value portion of a "--key=value" flag.

Parameters:

Name Type Description
arg const char * The full argument string (e.g. "--iterations=10").
key const char * The key to match, including leading dashes (e.g. "--iterations").

Returns: Pointer to the value substring after '=', or NULL if arg does not match key.