File: emscripten_console.c

package info (click to toggle)
emscripten 3.1.69%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 121,860 kB
  • sloc: ansic: 636,110; cpp: 425,974; javascript: 78,401; python: 58,404; sh: 49,154; pascal: 5,237; makefile: 3,366; asm: 2,415; lisp: 1,869
file content (79 lines) | stat: -rw-r--r-- 1,784 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright 2021 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */
#include <alloca.h>
#include <stdarg.h>
#include <stdio.h>

#include <emscripten/console.h>

static void vlogf(const char* fmt, va_list ap, void (*callback)(const char*)) {
  va_list ap2;
  va_copy(ap2, ap);
  size_t len = vsnprintf(0, 0, fmt, ap2);
  va_end(ap2);
  char* buf = alloca(len + 1);
  vsnprintf(buf, len + 1, fmt, ap);
  callback(buf);
}

void emscripten_console_logf(const char* fmt, ...) {
  va_list ap;
  va_start(ap, fmt);
  vlogf(fmt, ap, &emscripten_console_log);
  va_end(ap);
}

void emscripten_console_errorf(const char* fmt, ...) {
  va_list ap;
  va_start(ap, fmt);
  vlogf(fmt, ap, &emscripten_console_error);
  va_end(ap);
}

void emscripten_console_warnf(const char* fmt, ...) {
  va_list ap;
  va_start(ap, fmt);
  vlogf(fmt, ap, &emscripten_console_warn);
  va_end(ap);
}

void emscripten_console_tracef(const char* fmt, ...) {
  va_list ap;
  va_start(ap, fmt);
  vlogf(fmt, ap, &emscripten_console_trace);
  va_end(ap);
}

void emscripten_outf(const char* fmt, ...) {
  va_list ap;
  va_start(ap, fmt);
  vlogf(fmt, ap, &emscripten_out);
  va_end(ap);
}

void emscripten_errf(const char* fmt, ...) {
  va_list ap;
  va_start(ap, fmt);
  vlogf(fmt, ap, &emscripten_err);
  va_end(ap);
}

#ifndef NDEBUG
void emscripten_dbgf(const char* fmt, ...) {
  va_list ap;
  va_start(ap, fmt);
  vlogf(fmt, ap, &emscripten_dbg);
  va_end(ap);
}

void emscripten_dbg_backtracef(const char* fmt, ...) {
  va_list ap;
  va_start(ap, fmt);
  vlogf(fmt, ap, &emscripten_dbg_backtrace);
  va_end(ap);
}
#endif