common/utils: add tal_strdup_or_null helper.

It's not that uncommon to want to pass NULL through, for optional strings.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-07-22 16:42:57 +09:30
parent b6d347a6d3
commit 981d82c406
7 changed files with 22 additions and 34 deletions

View File

@@ -13,10 +13,7 @@ struct configvar *configvar_new(const tal_t *ctx,
const char *configline)
{
struct configvar *cv = tal(ctx, struct configvar);
if (file)
cv->file = tal_strdup(cv, file);
else
cv->file = NULL;
cv->file = tal_strdup_or_null(cv, file);
cv->src = src;
cv->linenum = linenum;
cv->configline = tal_strdup(cv, configline);