forked from drath/libratbag
Add xasprintf
Like asprintf, but leaves strp as NULL on failure Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
committed by
Benjamin Tissoires
parent
952eb1cf0e
commit
cb102e115c
@@ -171,3 +171,19 @@ ratbag_utf8_to_enc(char *buf, size_t buf_len, const char *to_enc,
|
||||
ssize_t
|
||||
ratbag_utf8_from_enc(char *in_buf, size_t in_len, const char *from_enc,
|
||||
char **out);
|
||||
|
||||
__attribute__((format(printf, 2, 3)))
|
||||
static inline int
|
||||
xasprintf(char **strp, const char *fmt, ...)
|
||||
{
|
||||
int rc = 0;
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
rc = vasprintf(strp, fmt, args);
|
||||
va_end(args);
|
||||
if ((rc == -1) && strp)
|
||||
*strp = NULL;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user