libplugin: add u16_option parsing

A couple of the fields for liquidity_ads are u16
This commit is contained in:
niftynei 2021-05-29 13:56:03 -05:00 committed by neil saitug
parent f668e72dd6
commit c934fe095b
2 changed files with 20 additions and 0 deletions

View File

@ -925,6 +925,25 @@ char *u32_option(const char *arg, u32 *i)
return NULL;
}
char *u16_option(const char *arg, u16 *i)
{
char *endp;
u64 n;
errno = 0;
n = strtoul(arg, &endp, 0);
if (*endp || !arg[0])
return tal_fmt(NULL, "'%s' is not a number", arg);
if (errno)
return tal_fmt(NULL, "'%s' is out of range", arg);
*i = n;
if (*i != n)
return tal_fmt(NULL, "'%s' is too large (overflow)", arg);
return NULL;
}
char *bool_option(const char *arg, bool *i)
{
if (!streq(arg, "true") && !streq(arg, "false"))

View File

@ -277,6 +277,7 @@ void plugin_notify_progress(struct command *cmd,
/* Standard helpers */
char *u64_option(const char *arg, u64 *i);
char *u32_option(const char *arg, u32 *i);
char *u16_option(const char *arg, u16 *i);
char *bool_option(const char *arg, bool *i);
char *charp_option(const char *arg, char **p);
char *flag_option(const char *arg, bool *i);