diff --git a/src/sys/syscall.c b/src/sys/syscall.c index 951683b..712b9fe 100644 --- a/src/sys/syscall.c +++ b/src/sys/syscall.c @@ -2519,8 +2519,18 @@ static const syscall_handler_fn sys_cmd_table[SYS_CMD_TABLE_SIZE] = { static uint64_t handle_sys_write(const syscall_args_t *args) { extern void cmd_write_len(const char *str, size_t len); process_t *proc = process_get_current(); + int fd = (int)args->arg1; const char *buf = (const char*)args->arg2; size_t len = (size_t)args->arg3; + + if (proc && fd >= 0 && fd < MAX_PROCESS_FDS && proc->fds[fd]) { + syscall_args_t fs_args = *args; + fs_args.arg2 = args->arg1; // fd + fs_args.arg3 = args->arg2; // buf + fs_args.arg4 = args->arg3; // len + return fs_cmd_write(&fs_args); + } + if (!proc || !proc->is_user) { cmd_write_len(buf, len); return len; diff --git a/src/userland/libc/posix_io.c b/src/userland/libc/posix_io.c index 3c52550..a159d46 100644 --- a/src/userland/libc/posix_io.c +++ b/src/userland/libc/posix_io.c @@ -391,13 +391,9 @@ __attribute__((weak)) ssize_t write(int fd, const void *buf, size_t count) { return (ssize_t)n; } - if (_b_is_stdio_handle(h)) { + n = sys_write_fs(h->kernel_fd, buf, (uint32_t)count); + if (n < 0 && _b_is_stdio_handle(h)) { n = sys_write(h->kernel_fd, (const char *)buf, (int)count); - } else { - n = sys_write_fs(h->kernel_fd, buf, (uint32_t)count); - if (n < 0) { - n = sys_write(h->kernel_fd, (const char *)buf, (int)count); - } } if (n < 0) { diff --git a/src/userland/libc/stdio.c b/src/userland/libc/stdio.c index 96020ef..52fe50d 100644 --- a/src/userland/libc/stdio.c +++ b/src/userland/libc/stdio.c @@ -152,10 +152,9 @@ size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) { return 0; } total = size * nmemb; - if (stream->fd <= 2) { + n = sys_write_fs(stream->fd, ptr, (uint32_t)total); + if (n < 0 && stream->fd <= 2) { n = sys_write(stream->fd, (const char *)ptr, (int)total); - } else { - n = sys_write_fs(stream->fd, ptr, (uint32_t)total); } if (n < 0) { stream->err = 1;