mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-08 10:08:05 +02:00
util: add strdup_printf helper functions
More straightforward than using xasprintf Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1156>
This commit is contained in:
parent
3858a6c4f8
commit
99ceda011c
1 changed files with 27 additions and 0 deletions
|
|
@ -154,6 +154,33 @@ xvasprintf(char **strp, const char *fmt, va_list args)
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__ ((format (printf, 1, 2)))
|
||||||
|
static inline char *
|
||||||
|
strdup_printf(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
int rc = 0;
|
||||||
|
va_list args;
|
||||||
|
char *strp;
|
||||||
|
|
||||||
|
va_start(args, fmt);
|
||||||
|
rc = vasprintf(&strp, fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
if (rc < 0)
|
||||||
|
abort();
|
||||||
|
return strp;
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((format (printf, 1, 0)))
|
||||||
|
static inline char *
|
||||||
|
strdup_vprintf(const char *fmt, va_list args)
|
||||||
|
{
|
||||||
|
char *strp;
|
||||||
|
int rc = xvasprintf(&strp, fmt, args);
|
||||||
|
if (rc < 0)
|
||||||
|
abort();
|
||||||
|
return strp;
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
safe_atoi_base(const char *str, int *val, int base)
|
safe_atoi_base(const char *str, int *val, int base)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue