mirror of https://github.com/mpv-player/mpv
ta_utils: add talloc_replace
Helper to replace a string with a new one without reallocating the buffer, if not needed.
This commit is contained in:
parent
077f05f7a1
commit
3edbd30798
10
ta/ta.h
10
ta/ta.h
|
@ -99,6 +99,16 @@ bool ta_vasprintf_append_buffer(char **str, const char *fmt, va_list ap) TA_PRF(
|
|||
#define ta_dup(ta_parent, ptr) \
|
||||
(TA_TYPEOF(ptr))ta_memdup(ta_parent, ptr, sizeof(*(ptr)))
|
||||
|
||||
#define ta_replace(ta_parent, str, replace) \
|
||||
do { \
|
||||
if (!(str)) { \
|
||||
(str) = ta_xstrdup((ta_parent), (replace)); \
|
||||
} else { \
|
||||
*(str) = '\0'; \
|
||||
ta_xstrdup_append(&(str), (replace)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// Ugly macros that crash on OOM.
|
||||
// All of these mirror real functions (with a 'x' added after the 'ta_'
|
||||
// prefix), and the only difference is that they will call abort() on allocation
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#define talloc_strndup ta_xstrndup
|
||||
#define talloc_asprintf ta_xasprintf
|
||||
#define talloc_vasprintf ta_xvasprintf
|
||||
#define talloc_replace ta_replace
|
||||
|
||||
// Don't define linker-level symbols, as that would clash with real libtalloc.
|
||||
#define talloc_strdup_append ta_talloc_strdup_append
|
||||
|
|
Loading…
Reference in New Issue