• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #include <stdarg.h>
7 #include <string.h>
8 
9 #include "drm_util.h"
10 #include "virgl_util.h"
11 
12 #include "util/macros.h"
13 
14 void
_drm_log(const char * fmt,...)15 _drm_log(const char *fmt, ...)
16 {
17    const char prefix[] = "drm: ";
18    char line[1024];
19    size_t len;
20    va_list va;
21    int ret;
22 
23    len = ARRAY_SIZE(prefix) - 1;
24    memcpy(line, prefix, len);
25 
26    va_start(va, fmt);
27    ret = vsnprintf(line + len, ARRAY_SIZE(line) - len, fmt, va);
28    va_end(va);
29 
30    if (ret < 0) {
31       const char log_error[] = "log error";
32       memcpy(line + len, log_error, ARRAY_SIZE(log_error) - 1);
33       len += ARRAY_SIZE(log_error) - 1;
34    } else if ((size_t)ret < ARRAY_SIZE(line) - len) {
35       len += ret;
36    } else {
37       len = ARRAY_SIZE(line) - 1;
38    }
39 
40    /* make room for newline */
41    if (len + 1 >= ARRAY_SIZE(line))
42       len--;
43 
44    line[len++] = '\n';
45    line[len] = '\0';
46 
47    virgl_log("%s", line);
48 }
49