weston-log: Return bytes written for 'printf()' and 'vprintf()' functions

Information is needed for 'vlog()' and 'vlog_continue()' (others
depend on them).

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
dev
Marius Vlad 6 years ago
parent 670ac1c0ed
commit 843b238551
  1. 4
      include/libweston/weston-log.h
  2. 15
      libweston/weston-log.c

@ -79,11 +79,11 @@ void
weston_log_scope_write(struct weston_log_scope *scope, weston_log_scope_write(struct weston_log_scope *scope,
const char *data, size_t len); const char *data, size_t len);
void int
weston_log_scope_vprintf(struct weston_log_scope *scope, weston_log_scope_vprintf(struct weston_log_scope *scope,
const char *fmt, va_list ap); const char *fmt, va_list ap);
void int
weston_log_scope_printf(struct weston_log_scope *scope, weston_log_scope_printf(struct weston_log_scope *scope,
const char *fmt, ...) const char *fmt, ...)
__attribute__ ((format (printf, 2, 3))); __attribute__ ((format (printf, 2, 3)));

@ -753,16 +753,16 @@ weston_log_scope_write(struct weston_log_scope *scope,
* *
* \memberof weston_log_scope * \memberof weston_log_scope
*/ */
WL_EXPORT void WL_EXPORT int
weston_log_scope_vprintf(struct weston_log_scope *scope, weston_log_scope_vprintf(struct weston_log_scope *scope,
const char *fmt, va_list ap) const char *fmt, va_list ap)
{ {
static const char oom[] = "Out of memory"; static const char oom[] = "Out of memory";
char *str; char *str;
int len; int len = 0;
if (!weston_log_scope_is_enabled(scope)) if (!weston_log_scope_is_enabled(scope))
return; return len;
len = vasprintf(&str, fmt, ap); len = vasprintf(&str, fmt, ap);
if (len >= 0) { if (len >= 0) {
@ -771,6 +771,8 @@ weston_log_scope_vprintf(struct weston_log_scope *scope,
} else { } else {
weston_log_scope_write(scope, oom, sizeof oom - 1); weston_log_scope_write(scope, oom, sizeof oom - 1);
} }
return len;
} }
/** Write a formatted string for a scope /** Write a formatted string for a scope
@ -786,15 +788,18 @@ weston_log_scope_vprintf(struct weston_log_scope *scope,
* *
* \memberof weston_log_scope * \memberof weston_log_scope
*/ */
WL_EXPORT void WL_EXPORT int
weston_log_scope_printf(struct weston_log_scope *scope, weston_log_scope_printf(struct weston_log_scope *scope,
const char *fmt, ...) const char *fmt, ...)
{ {
va_list ap; va_list ap;
int len;
va_start(ap, fmt); va_start(ap, fmt);
weston_log_scope_vprintf(scope, fmt, ap); len = weston_log_scope_vprintf(scope, fmt, ap);
va_end(ap); va_end(ap);
return len;
} }
/** Write a formatted string for a subscription /** Write a formatted string for a subscription

Loading…
Cancel
Save