src/basic: add yet another strdup helper

It's a bit ugly to have both strdup_to() and strdup_to_full(). I initially
started with one variant, but then in some functions we want the additional
info, while in many other places, having 1 instead of 0 causes the return
value of whole chains of functions to be changed. It *probably* wouldn't cause
any difference, but there is at least of bunch of tests that would need to be
updated, so in the end it seems to have the two variants.

The output param is first to match free_and_strdup() and other similar
functions.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2024-03-15 13:16:51 +01:00
parent fb01ab09d3
commit 892c5902ae
3 changed files with 53 additions and 0 deletions

View File

@@ -224,6 +224,12 @@ static inline int free_and_strdup_warn(char **p, const char *s) {
}
int free_and_strndup(char **p, const char *s, size_t l);
int strdup_to_full(char **ret, const char *src);
static inline int strdup_to(char **ret, const char *src) {
int r = strdup_to_full(ASSERT_PTR(ret), src);
return r < 0 ? r : 0; /* Suppress return value of 1. */
}
bool string_is_safe(const char *p) _pure_;
DISABLE_WARNING_STRINGOP_TRUNCATION;