xref: /aosp_15_r20/external/virglrenderer/src/proxy/proxy_common.c (revision bbecb9d118dfdb95f99bd754f8fa9be01f189df3)
1 /*
2  * Copyright 2021 Google LLC
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #include "proxy_common.h"
7 
8 #include <stdarg.h>
9 #include <stdio.h>
10 
11 struct proxy_renderer proxy_renderer;
12 
13 void
proxy_log(const char * fmt,...)14 proxy_log(const char *fmt, ...)
15 {
16    const char prefix[] = "proxy: ";
17    char line[1024];
18    size_t len;
19    va_list va;
20    int ret;
21 
22    len = ARRAY_SIZE(prefix) - 1;
23    memcpy(line, prefix, len);
24 
25    va_start(va, fmt);
26    ret = vsnprintf(line + len, ARRAY_SIZE(line) - len, fmt, va);
27    va_end(va);
28 
29    if (ret < 0) {
30       const char log_error[] = "log error";
31       memcpy(line + len, log_error, ARRAY_SIZE(log_error) - 1);
32       len += ARRAY_SIZE(log_error) - 1;
33    } else if ((size_t)ret < ARRAY_SIZE(line) - len) {
34       len += ret;
35    } else {
36       len = ARRAY_SIZE(line) - 1;
37    }
38 
39    /* make room for newline */
40    if (len + 1 >= ARRAY_SIZE(line))
41       len--;
42 
43    line[len++] = '\n';
44    line[len] = '\0';
45 
46    virgl_log("%s", line);
47 }
48