mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
user-notification: config: various small cleanups
* Rename user_notification_add() to user_notification_add_fmt() * Add new user_notification_add() helper function * Use xvasprintf() to replace user_notification_add_va() * Make better use of helper functions in config.c
This commit is contained in:
parent
0686f94b18
commit
759bc8007b
3 changed files with 25 additions and 44 deletions
|
|
@ -1,38 +1,14 @@
|
|||
#include "user-notification.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "xmalloc.h"
|
||||
|
||||
static bool
|
||||
user_notification_add_va(user_notifications_t *notifications,
|
||||
enum user_notification_kind kind, const char *fmt,
|
||||
va_list ap)
|
||||
{
|
||||
va_list ap2;
|
||||
va_copy(ap2, ap);
|
||||
int cnt = vsnprintf(NULL, 0, fmt, ap2);
|
||||
va_end(ap2);
|
||||
|
||||
if (cnt < 0)
|
||||
return false;
|
||||
|
||||
char *text = malloc(cnt + 1);
|
||||
vsnprintf(text, cnt + 1, fmt, ap);
|
||||
|
||||
struct user_notification not = {
|
||||
.kind = kind,
|
||||
.text = text,
|
||||
};
|
||||
tll_push_back(*notifications, not);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
user_notification_add(user_notifications_t *notifications,
|
||||
void
|
||||
user_notification_add_fmt(user_notifications_t *notifications,
|
||||
enum user_notification_kind kind, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
bool ret = user_notification_add_va(notifications, kind, fmt, ap);
|
||||
char *text = xvasprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
user_notification_add(notifications, kind, text);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue