diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-02-14 10:17:08 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-02-14 10:17:08 +0000 |
| commit | 689a4cc741f2dbb2dbefc16ab817438c953b568c (patch) | |
| tree | 8368a8c7485136e3b5e17f654b2603b7c25cc470 /user-notification.c | |
| parent | Merge branch 'url-hint-letters' (diff) | |
| parent | client: -D,--working-directory: check path exists and is a directory (diff) | |
Merge branch 'working-dir-command-line-option'
Closes #347
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; +} |
