diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-02-11 11:47:29 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-02-11 11:53:35 +0100 |
| commit | d996bc9b9bc2f06c99d09071f53ac4870f91cc78 (patch) | |
| tree | 3fc64307fcb90571d0a8be31b9f27f1877d2521c | |
| parent | 8a1e73a70bc1a911a53ceca95b182bd9fd9f7089 (diff) | |
| download | pintos-d996bc9b9bc2f06c99d09071f53ac4870f91cc78.tar.gz | |
implement write
| -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 |
