weston-log: Return bytes written for 'printf()' and 'vprintf()' functions
authorMarius Vlad <marius.vlad@collabora.com>
Tue, 6 Aug 2019 14:37:51 +0000 (17:37 +0300)
committerMarius Vlad <marius.vlad@collabora.com>
Mon, 19 Aug 2019 09:40:42 +0000 (12:40 +0300)
Information is needed for 'vlog()' and 'vlog_continue()' (others
depend on them).

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
include/libweston/weston-log.h
libweston/weston-log.c

index f896d224d7f457e34e8b8bdce713cad8d8556a2e..50afbeb0613da1f0dad6857abc9cc783a85628b6 100644 (file)
@@ -79,11 +79,11 @@ void
 weston_log_scope_write(struct weston_log_scope *scope,
                         const char *data, size_t len);
 
-void
+int
 weston_log_scope_vprintf(struct weston_log_scope *scope,
                           const char *fmt, va_list ap);
 
-void
+int
 weston_log_scope_printf(struct weston_log_scope *scope,
                          const char *fmt, ...)
                          __attribute__ ((format (printf, 2, 3)));
index 30018bf579050567ab941c62ad2b9f89847cc926..3584462b01b9f6c3bcb272f63ce067ad9ced2b3e 100644 (file)
@@ -753,16 +753,16 @@ weston_log_scope_write(struct weston_log_scope *scope,
  *
  * \memberof weston_log_scope
  */
-WL_EXPORT void
+WL_EXPORT int
 weston_log_scope_vprintf(struct weston_log_scope *scope,
                         const char *fmt, va_list ap)
 {
        static const char oom[] = "Out of memory";
        char *str;
-       int len;
+       int len = 0;
 
        if (!weston_log_scope_is_enabled(scope))
-               return;
+               return len;
 
        len = vasprintf(&str, fmt, ap);
        if (len >= 0) {
@@ -771,6 +771,8 @@ weston_log_scope_vprintf(struct weston_log_scope *scope,
        } else {
                weston_log_scope_write(scope, oom, sizeof oom - 1);
        }
+
+       return len;
 }
 
 /** Write a formatted string for a scope
@@ -786,15 +788,18 @@ weston_log_scope_vprintf(struct weston_log_scope *scope,
  *
  * \memberof weston_log_scope
  */
-WL_EXPORT void
+WL_EXPORT int
 weston_log_scope_printf(struct weston_log_scope *scope,
                          const char *fmt, ...)
 {
        va_list ap;
+       int len;
 
        va_start(ap, fmt);
-       weston_log_scope_vprintf(scope, fmt, ap);
+       len = weston_log_scope_vprintf(scope, fmt, ap);
        va_end(ap);
+
+       return len;
 }
 
 /** Write a formatted string for a subscription