-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint.c
60 lines (42 loc) · 1.06 KB
/
print.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
56
57
58
59
60
#include <uefi.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#define PRINT(x) st->ConOut->OutputString(st->ConOut, (x))
size_t efi_strlen(const char16_t *str) {
size_t ret = 0;
for(; *str; ret++, str++);
return ret;
}
efi_status efi_print(const char *str) {
return efi_printn(str, strlen(str));
}
efi_status efi_printn(const char *str, size_t n) {
size_t i = 0;
for(const char *s = str; *s && i < n; s++, i++) {
uint16_t out[2] = { (uint16_t) *s, 0 };
if(*s == '\n') {
uint16_t nl[2] = { '\r', '\0' };
efi_status status = PRINT((char16_t *) nl);
if(EFI_ERROR(status)) {
return status;
}
}
efi_status status = PRINT((char16_t *) out);
if(EFI_ERROR(status)) {
return status;
}
}
return EFI_SUCCESS;
}
static size_t callback(void *ctx __attribute__((unused)), const char *string, size_t length) {
efi_printn(string, length);
return length;
}
int efi_printf(const char *restrict format, ...) {
va_list list;
va_start(list, format);
int ret = vcbprintf(NULL, callback, format, list);
va_end(list);
return ret;
}