Skip to content

Commit

Permalink
Merge pull request #68 from hangpark/iss/16
Browse files Browse the repository at this point in the history
[#16] Implement tell system call
  • Loading branch information
hangpark authored Apr 12, 2017
2 parents 8fda4d3 + 8e23bbf commit 0344cc7
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/userprog/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,27 @@ syscall_seek (int fd, unsigned position)
lock_release (&filesys_lock);
}

/* Returns the position of the next byte to be read or written
in open file fd, expressed in bytes from the beginning
of the file. */
static unsigned
syscall_tell (int fd)
{
return 1;
/* Open the file. */
lock_acquire (&filesys_lock);
struct file *file = process_get_file (fd);
if (file == NULL)
{
lock_release (&filesys_lock);
return -1;
}

/* Get the position. */
unsigned position = file_tell (file);

/* Return the position. */
lock_release (&filesys_lock);
return position;
}

/* Closes file descriptor. */
Expand Down

0 comments on commit 0344cc7

Please sign in to comment.