1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:38:11 +00:00
serenity/LibC/entry.cpp
Andreas Kling 8605711f4b Make /bin/clear work again.
After I made stdio buffered, we were dropping anything unflushed on exit.
Since /bin/clear just prints out some escape sequences without a newline,
the entire buffer was being discarded.

Also add VirtualConsole::clear() that handles clearing of background VC's.
2018-11-10 00:56:10 +01:00

52 lines
1.1 KiB
C++

#include <stdio.h>
#include <string.h>
#include <Kernel/Syscall.h>
#include <AK/StringImpl.h>
extern "C" int main(int, char**);
FILE __default_streams[3];
int errno;
FILE* stdin;
FILE* stdout;
FILE* stderr;
char** environ;
extern "C" void __malloc_init();
extern "C" int _start()
{
errno = 0;
memset(__default_streams, 0, sizeof(__default_streams));
__default_streams[0].fd = 0;
stdin = &__default_streams[0];
__default_streams[1].fd = 1;
stdout = &__default_streams[1];
__default_streams[2].fd = 2;
stderr = &__default_streams[2];
__malloc_init();
StringImpl::initializeGlobals();
int status = 254;
int argc;
char** argv;
int rc = Syscall::invoke(Syscall::SC_get_arguments, (dword)&argc, (dword)&argv);
if (rc < 0)
goto epilogue;
rc = Syscall::invoke(Syscall::SC_get_environment, (dword)&environ);
if (rc < 0)
goto epilogue;
status = main(argc, argv);
fflush(stdout);
fflush(stderr);
epilogue:
Syscall::invoke(Syscall::SC_exit, status);
// Birger's birthday <3
return 20150614;
}