Fixed stdio file descriptors not being initialised properly

This commit is contained in:
2021-12-25 22:04:19 +00:00
parent 60a897d464
commit 27933e1a79
3 changed files with 11 additions and 3 deletions

View File

@@ -26,8 +26,8 @@ typedef struct __io_file FILE;
extern FILE *__get_stdio_file(int);
#define stdin (__get_stdio_file(0))
#define stdout (__get_stdio_file(0))
#define stderr (__get_stdio_file(0))
#define stdout (__get_stdio_file(1))
#define stderr (__get_stdio_file(2))
extern FILE *fopen(const char *path, const char *mode);
extern FILE *freopen(const char *path, const char *mode, FILE *fp);

View File

@@ -164,6 +164,8 @@ static void init_stdio(mx_bootstrap_handle_t *handles, size_t nhandles)
init_stdio_fd(i, fd_handles[i], n);
}
__fio_init(0, 1, 2);
}
int __crt_init(mx_handle_t bootstrap)
@@ -208,10 +210,12 @@ int __crt_init(mx_handle_t bootstrap)
#endif
init_stdio(start_handles, nr_handles);
int ret = main(msg->args_num, argv);
__crt_run_atexit();
mio_destroy_global_fd_list();
mio_fd_cleanup();
mio_fs_cleanup();
mx_task_kill(mx_bootstrap_handle_get(MX_B_TASK_SELF), ret);
/* unreachable */

View File

@@ -10,6 +10,7 @@ ssize_t read(int fd, void *buf, size_t count)
return -1;
}
__set_errno(0);
return ret;
}
@@ -21,6 +22,7 @@ ssize_t write(int fd, const void *buf, size_t count)
return -1;
}
__set_errno(0);
return ret;
}
@@ -32,6 +34,7 @@ int open(const char *pathname, int flags)
return -1;
}
__set_errno(0);
return ret;
}
@@ -43,5 +46,6 @@ int close(int fd)
return -1;
}
__set_errno(0);
return ret;
}