mirror of https://github.com/flysand7/ciabatta.git
close all streams on exit
This commit is contained in:
parent
673a363d4b
commit
25db1abb6e
|
@ -11,3 +11,4 @@ void _setup_timer(void);
|
|||
void _setup_eh();
|
||||
void _setup_heap();
|
||||
void _setup_io();
|
||||
void _close_io();
|
||||
|
|
|
@ -87,9 +87,21 @@ void mainCRTStartup() {
|
|||
int exit_code = main(argc, args);
|
||||
|
||||
// we call exit because we want atexit routines run
|
||||
// and all the file handles to be freed
|
||||
exit(exit_code);
|
||||
}
|
||||
|
||||
_Noreturn void exit(int status) {
|
||||
for (int i = atexit_func_count; i--;) {
|
||||
atexit_funcs[i]();
|
||||
}
|
||||
_close_io();
|
||||
ExitProcess(status);
|
||||
}
|
||||
|
||||
_Noreturn void _Exit(int status) {
|
||||
ExitProcess(status);
|
||||
}
|
||||
|
||||
_Noreturn void abort(void) {
|
||||
raise(SIGABRT);
|
||||
|
@ -104,17 +116,6 @@ int atexit(void (*func)(void)) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
_Noreturn void exit(int status) {
|
||||
for (int i = atexit_func_count; i--;) {
|
||||
atexit_funcs[i]();
|
||||
}
|
||||
ExitProcess(status);
|
||||
}
|
||||
|
||||
_Noreturn void _Exit(int status) {
|
||||
ExitProcess(status);
|
||||
}
|
||||
|
||||
char *getenv(const char *name) {
|
||||
// The string pointed to shall not be modified by the program, but may be
|
||||
// overwritten by a subsequent call to the getenv function
|
||||
|
|
|
@ -112,6 +112,13 @@ void _setup_io() {
|
|||
stdin = new_file(hstdin, NULL, STR_R, 0, 0, _IONBF, 0, NULL);
|
||||
}
|
||||
|
||||
void _close_io() {
|
||||
while(file_list_last != NULL) {
|
||||
fflush(file_list_last);
|
||||
dispose_file(file_list_last);
|
||||
}
|
||||
}
|
||||
|
||||
int setvbuf(
|
||||
FILE *restrict stream,
|
||||
char *restrict buf,
|
||||
|
@ -139,6 +146,16 @@ int setvbuf(
|
|||
return 0;
|
||||
}
|
||||
|
||||
int fflush(FILE *stream) {
|
||||
if(mode == _IOFBF) {
|
||||
|
||||
}
|
||||
else if(mode == _IONBF) {
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void setbuf(FILE *restrict stream, char *restrict buf) {
|
||||
if(buf != NULL)
|
||||
setvbuf(stream, buf, _IOFBF, BUFSIZ);
|
||||
|
|
Loading…
Reference in New Issue