diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-02-12 08:25:29 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-02-12 20:42:53 +0000 |
| commit | 2a99c5a093737b7905d71ee2df24d3a17b1d83e2 (patch) | |
| tree | 5f8c7f505ab1fd98714e3fb543127351b4a03289 /user-notification.c | |
| parent | Merge branch 'releases/1.6' (diff) | |
user-notification: add new function ‘user_notification_add()’
Diffstat (limited to 'user-notification.c')
| -rw-r--r-- | user-notification.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/user-notification.c b/user-notification.c new file mode 100644 index 00000000..497aa08c --- /dev/null +++ b/user-notification.c @@ -0,0 +1,38 @@ +#include "user-notification.h" +#include <stdio.h> +#include <stdarg.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, + 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); + va_end(ap); + return ret; +} |
