wired
libc-free QUIC/HTTP3 SDK in C for x86_64-linux
Loading...
Searching...
No Matches
cliargs.h File Reference

Parse already-materialized argc/argv for named flags of the form --flag value. More...

Go to the source code of this file.

Functions

i64 wired_cliargs_int (int argc, char **argv, const char *flag, i64 defval)
 Find flag in argv and parse its following element as a non-negative base-10 integer.
const char * wired_cliargs_str (int argc, char **argv, const char *flag, const char *defval)
 Find flag in argv and return a pointer to its following element.
int wired_cliargs_flag (int argc, char **argv, const char *flag)
 Find flag anywhere in argv, including argv's last element (unlike wired_cliargs_int/wired_cliargs_str, no following value is expected).
int wired_cliargs_ipv4 (const char *s, u8 out[4])
 Parse a dotted-decimal IPv4 address ("a.b.c.d") into 4 bytes.

Detailed Description

Parse already-materialized argc/argv for named flags of the form --flag value.

No libc: no getopt, no strtol, no strcmp.

This module only parses argv it is handed — it does not read the kernel stack itself. See cliargs.c's file comment for why raw stack extraction (from _start) is out of scope here.

Function Documentation

◆ wired_cliargs_flag()

int wired_cliargs_flag ( int argc,
char ** argv,
const char * flag )

Find flag anywhere in argv, including argv's last element (unlike wired_cliargs_int/wired_cliargs_str, no following value is expected).

Parameters
argcargument count
argvargument vector
flagNUL-terminated flag to search for, e.g. "--verbose"
Returns
1 if flag is present in argv, 0 otherwise

◆ wired_cliargs_int()

i64 wired_cliargs_int ( int argc,
char ** argv,
const char * flag,
i64 defval )

Find flag in argv and parse its following element as a non-negative base-10 integer.

Parameters
argcargument count
argvargument vector (argv[0] is the program name, as usual)
flagNUL-terminated flag to search for, e.g. "--port"
defvalvalue returned when the flag is absent, dangling (no following element), or its value is not purely digits
Returns
the parsed value, or defval

◆ wired_cliargs_ipv4()

int wired_cliargs_ipv4 ( const char * s,
u8 out[4] )

Parse a dotted-decimal IPv4 address ("a.b.c.d") into 4 bytes.

Rejects (leaving out unchanged): any octet outside 0-255, a segment count other than 4, an empty segment, a non-digit character, or trailing garbage after the last octet. Leading zeros are accepted.

Parameters
sNUL-terminated dotted-decimal string
out4-byte buffer receiving the parsed octets on success
Returns
1 on success, 0 on any parse error

◆ wired_cliargs_str()

const char * wired_cliargs_str ( int argc,
char ** argv,
const char * flag,
const char * defval )

Find flag in argv and return a pointer to its following element.

Parameters
argcargument count
argvargument vector
flagNUL-terminated flag to search for, e.g. "--cert"
defvalvalue returned when the flag is absent or dangling
Returns
argv[i+1] where argv[i] == flag, or defval