91 lines
3.3 KiB
Diff
91 lines
3.3 KiB
Diff
|
From 1435bd3583935bd010b391c2436bfedb4bf31f63 Mon Sep 17 00:00:00 2001
|
||
|
From: Clayton Craft <clayton@craftyguy.net>
|
||
|
Date: Fri, 6 Oct 2023 08:30:52 -0700
|
||
|
Subject: [PATCH 2/2] fix wchar for compiling on musl
|
||
|
|
||
|
---
|
||
|
src/boot/efi/efi-string.c | 10 +++++-----
|
||
|
src/boot/efi/efi.h | 5 ++---
|
||
|
2 files changed, 7 insertions(+), 8 deletions(-)
|
||
|
|
||
|
diff --git a/src/boot/efi/efi-string.c b/src/boot/efi/efi-string.c
|
||
|
index 4400591255..f630f628f8 100644
|
||
|
--- a/src/boot/efi/efi-string.c
|
||
|
+++ b/src/boot/efi/efi-string.c
|
||
|
@@ -480,7 +480,7 @@ typedef struct {
|
||
|
bool have_field_width;
|
||
|
|
||
|
const char *str;
|
||
|
- const wchar_t *wstr;
|
||
|
+ const uint16_t *wstr;
|
||
|
|
||
|
/* For numbers. */
|
||
|
bool is_signed;
|
||
|
@@ -541,7 +541,7 @@ static bool push_str(FormatContext *ctx, SpecifierContext *sp) {
|
||
|
push_padding(ctx, ' ', sp->padded_len);
|
||
|
|
||
|
/* In userspace unit tests we cannot just memcpy() the wide string. */
|
||
|
- if (sp->wstr && sizeof(wchar_t) == sizeof(char16_t)) {
|
||
|
+ if (sp->wstr && sizeof(uint16_t) == sizeof(char16_t)) {
|
||
|
memcpy(ctx->buf + ctx->n, sp->wstr, sp->len * sizeof(*sp->wstr));
|
||
|
ctx->n += sp->len;
|
||
|
} else
|
||
|
@@ -633,7 +633,7 @@ static bool handle_format_specifier(FormatContext *ctx, SpecifierContext *sp) {
|
||
|
* int in vararg functions, which is why we fetch only ints for any such types. The compiler would
|
||
|
* otherwise warn about fetching smaller types. */
|
||
|
assert_cc(sizeof(int) == 4);
|
||
|
- assert_cc(sizeof(wchar_t) <= sizeof(int));
|
||
|
+ assert_cc(sizeof(uint16_t) <= sizeof(int));
|
||
|
assert_cc(sizeof(intmax_t) <= sizeof(long long));
|
||
|
|
||
|
assert(ctx);
|
||
|
@@ -728,13 +728,13 @@ static bool handle_format_specifier(FormatContext *ctx, SpecifierContext *sp) {
|
||
|
return push_str(ctx, sp);
|
||
|
|
||
|
case 'c':
|
||
|
- sp->wstr = &(wchar_t){ va_arg(ctx->ap, int) };
|
||
|
+ sp->wstr = &(uint16_t){ va_arg(ctx->ap, int) };
|
||
|
sp->len = 1;
|
||
|
return push_str(ctx, sp);
|
||
|
|
||
|
case 's':
|
||
|
if (sp->long_arg) {
|
||
|
- sp->wstr = va_arg(ctx->ap, const wchar_t *) ?: L"(null)";
|
||
|
+ sp->wstr = va_arg(ctx->ap, const uint16_t *) ?: L"(null)";
|
||
|
sp->len = wcsnlen(sp->wstr, sp->len);
|
||
|
} else {
|
||
|
sp->str = va_arg(ctx->ap, const char *) ?: "(null)";
|
||
|
diff --git a/src/boot/efi/efi.h b/src/boot/efi/efi.h
|
||
|
index 5c34668383..a0b48e7a96 100644
|
||
|
--- a/src/boot/efi/efi.h
|
||
|
+++ b/src/boot/efi/efi.h
|
||
|
@@ -10,7 +10,7 @@
|
||
|
|
||
|
#if SD_BOOT
|
||
|
/* uchar.h/wchar.h are not suitable for freestanding environments. */
|
||
|
-typedef __WCHAR_TYPE__ wchar_t;
|
||
|
+typedef __WCHAR_TYPE__ uint16_t;
|
||
|
typedef __CHAR16_TYPE__ char16_t;
|
||
|
typedef __CHAR32_TYPE__ char32_t;
|
||
|
|
||
|
@@ -21,7 +21,7 @@ assert_cc(sizeof(uint8_t) == 1);
|
||
|
assert_cc(sizeof(uint16_t) == 2);
|
||
|
assert_cc(sizeof(uint32_t) == 4);
|
||
|
assert_cc(sizeof(uint64_t) == 8);
|
||
|
-assert_cc(sizeof(wchar_t) == 2);
|
||
|
+assert_cc(sizeof(uint16_t) == 2);
|
||
|
assert_cc(sizeof(char16_t) == 2);
|
||
|
assert_cc(sizeof(char32_t) == 4);
|
||
|
assert_cc(sizeof(size_t) == sizeof(void *));
|
||
|
@@ -32,7 +32,6 @@ assert_cc(sizeof(size_t) == sizeof(uintptr_t));
|
||
|
# endif
|
||
|
#else
|
||
|
# include <uchar.h>
|
||
|
-# include <wchar.h>
|
||
|
#endif
|
||
|
|
||
|
/* We use size_t/ssize_t to represent UEFI UINTN/INTN. */
|
||
|
--
|
||
|
2.40.1
|
||
|
|