Replace strdup_or_null() by strdup_to()

I didn't know that this helper existed… It is very similar to strdup_to_full(),
but all callers can actually be replaced by strdup_to(), which has more fitting
semantics.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2024-03-19 21:08:52 +01:00
parent f174b294f6
commit 6a705f1234
7 changed files with 17 additions and 43 deletions

View File

@@ -303,25 +303,4 @@ bool version_is_valid_versionspec(const char *s);
ssize_t strlevenshtein(const char *x, const char *y);
static inline int strdup_or_null(const char *s, char **ret) {
char *c;
assert(ret);
/* This is a lot like strdup(), but is happy with NULL strings, and does not treat that as error, but
* copies the NULL value. */
if (!s) {
*ret = NULL;
return 0;
}
c = strdup(s);
if (!c)
return -ENOMEM;
*ret = c;
return 1;
}
char *strrstr(const char *haystack, const char *needle);