mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 08:25:20 +09:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user