Newlib does not flush stdout at end of execution
Posted: Fri Jan 17, 2020 11:55 am
Hello, I have a problem with newlib: I'm trying to compile a very simple program for my kernem:
But this code doesn't display anything on the screen unless I explicitly clear stdout. I debugged a bit my program with gdb and I realized that no destructor was called (there is no one) when exit is called, why ? Normally the buffers are emptied when the program ends, right?
My crt0.c code:
Thank you in advance!
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
int main(int argc, char *argv[])
{
struct dirent *dirent = NULL;
char *directory_path = ".";
DIR * directory = NULL;
if(argc >= 2)
directory_path = argv[1];
directory = opendir(directory_path);
if(!directory)
{printf("Impossible d'ouvrir le répertoire %s", directory_path); return -1;}
while ((dirent = readdir(directory)) != NULL)
printf("%s\n", dirent->d_name);
closedir(directory);
return 0;
}
My crt0.c code:
Code: Select all
#include <fcntl.h>
#include <stdlib.h>
#include "syscalls.h"
extern char end;
extern char **environ;
extern void exit(int code);
extern int brk(void * addr);
extern void __libc_init_array();
extern void __libc_fini_array();
extern int main(int argc, char ** argv, char ** envp);
extern void _init(void);
void _start(int args)
{
int *params = &args - 1;
int argc = *params;
char **argv = (char **) (params + 1);
environ = argv + argc + 1;
brk(&end); // Initialise le heap
__libc_init_array(); // Appelle les constructeurs
atexit(__libc_fini_array);
exit(main(argc, argv, environ));
}