1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-05 20:14:57 +00: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:
Liav A 2023-02-26 18:33:59 +02:00 committed by Andrew Kaster
parent 5416a37fde
commit 77486a0d08
3 changed files with 2 additions and 42 deletions

View File

@ -9,7 +9,6 @@
#include <AK/StringBuilder.h>
#include <AK/StringView.h>
#include <Kernel/KBuffer.h>
#include <stdarg.h>
namespace Kernel {

View File

@ -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)

View File

@ -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();
}