diff options
Diffstat (limited to 'src/userprog/syscall.c')
| -rw-r--r-- | src/userprog/syscall.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 3a780c6..2116e5c 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -114,8 +114,26 @@ read (int fd_i, void *buf, unsigned size) static int write (int fd_i, const void *buf, unsigned size) { - printf ("write: %s", (char *)buf); - return 0; + struct thread *thread = thread_current (); + + if (fd_i == 1) { + // stdout + putbuf ((const char *)buf, size); + return size; + } else if (fd_i == 0) { + printf ("[%s] write: tried to write to stdin\n", thread->name); + return -1; + } + + struct file *file = get_file (thread, fd_i); + if (!file) { + return -1; + } + + int n = file_write(file, buf, size); + printf ("%d/%d: %s\n", n, size, (char *)buf); + + return n; } static void |
