forked from cloudius-systems/osv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkprintf.c
55 lines (47 loc) · 1.06 KB
/
kprintf.c
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
/*
* Copyright (C) 2013 Cloudius Systems, Ltd.
*
* This work is open source software, licensed under the terms of the
* BSD license as described in the LICENSE file in the top-level directory.
*/
/*
* A printf variant that prints directly to the kernel console.
*/
#include <osv/debug.h>
#include "../libc/stdio/stdio_impl.h"
#include <assert.h>
#include <limits.h>
#include <string.h>
#include <errno.h>
#include <stdint.h>
#include <sys/uio.h>
static size_t wrap_write(FILE *f, const unsigned char *buf, size_t len)
{
if (f->wpos-f->wbase)
debug_write((const char *)f->wbase, f->wpos-f->wbase);
debug_write((const char *)buf, len);
f->wend = f->buf + f->buf_size;
f->wpos = f->wbase = f->buf;
return len;
}
int vkprintf(const char *restrict fmt, va_list ap)
{
FILE f = {
.fd = 1,
.lbf = EOF,
.write = wrap_write,
.buf = (void *)fmt,
.buf_size = 0,
.no_locking = true,
};
return vfprintf(&f, fmt, ap);
}
int kprintf(const char *restrict fmt, ...)
{
int ret;
va_list ap;
va_start(ap, fmt);
ret = vkprintf(fmt, ap);
va_end(ap);
return ret;
}