mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
Kernel: Remove includes to LibC stdarg definitions
We don't actually need the va_list and other stdarg definitions in the kernel, because we actually don't use the "pure" printf interface in any kernel code at all, but we retain the snprintf declaration because the libstdc++ library still need it to be declared and extern'ed.
This commit is contained in:
parent
5416a37fde
commit
77486a0d08
Notes:
sideshowbarker
2024-07-17 06:29:49 +09:00
Author: https://github.com/supercomputer7 Commit: https://github.com/SerenityOS/serenity/commit/77486a0d08 Pull-request: https://github.com/SerenityOS/serenity/pull/17634 Reviewed-by: https://github.com/ADKaster
@ -9,7 +9,6 @@
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/KBuffer.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
|
@ -20,8 +20,6 @@
|
||||
#include <Kernel/TTY/ConsoleManagement.h>
|
||||
#include <Kernel/kstdio.h>
|
||||
|
||||
#include <LibC/stdarg.h>
|
||||
|
||||
namespace Kernel {
|
||||
extern Atomic<Graphics::Console*> g_boot_console;
|
||||
}
|
||||
@ -90,49 +88,13 @@ static void console_out(char ch)
|
||||
}
|
||||
}
|
||||
|
||||
static void buffer_putch(char*& bufptr, char ch)
|
||||
{
|
||||
*bufptr++ = ch;
|
||||
}
|
||||
|
||||
// Declare it, so that the symbol is exported, because libstdc++ uses it.
|
||||
// However, *only* libstdc++ uses it, and none of the rest of the Kernel.
|
||||
extern "C" int sprintf(char* buffer, char const* fmt, ...);
|
||||
|
||||
int sprintf(char* buffer, char const* fmt, ...)
|
||||
int sprintf(char*, char const*, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
int ret = printf_internal(buffer_putch, buffer, fmt, ap);
|
||||
buffer[ret] = '\0';
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int snprintf(char* buffer, size_t size, char const* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
size_t space_remaining = 0;
|
||||
if (size) {
|
||||
space_remaining = size - 1;
|
||||
} else {
|
||||
space_remaining = 0;
|
||||
}
|
||||
auto sized_buffer_putch = [&](char*& bufptr, char ch) {
|
||||
if (space_remaining) {
|
||||
*bufptr++ = ch;
|
||||
--space_remaining;
|
||||
}
|
||||
};
|
||||
int ret = printf_internal(sized_buffer_putch, buffer, fmt, ap);
|
||||
if (space_remaining) {
|
||||
buffer[ret] = '\0';
|
||||
} else if (size > 0) {
|
||||
buffer[size - 1] = '\0';
|
||||
}
|
||||
va_end(ap);
|
||||
return ret;
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
static inline void internal_dbgputch(char ch)
|
||||
|
@ -15,7 +15,6 @@ void kernelputstr(char const*, size_t);
|
||||
void kernelcriticalputstr(char const*, size_t);
|
||||
void dbgputchar(char);
|
||||
void kernelearlyputstr(char const*, size_t);
|
||||
int snprintf(char* buf, size_t, char const* fmt, ...) __attribute__((format(printf, 3, 4)));
|
||||
void set_serial_debug_enabled(bool desired_state);
|
||||
bool is_serial_debug_enabled();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user