Skip to content

Commit

Permalink
[#17] Implement close system call
Browse files Browse the repository at this point in the history
  • Loading branch information
hangpark committed Apr 12, 2017
1 parent 7e015a8 commit 2fa247d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/userprog/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,24 @@ syscall_tell (int fd)
return 1;
}

/* Closes file descriptor. */
static void
syscall_close (int fd)
{

lock_acquire (&filesys_lock);
struct list *list = &process_current ()->file_list;
struct list_elem *e;
for (e = list_begin (list); e != list_end (list); e = list_next (e))
{
struct process_file *pfe = list_entry (e, struct process_file, elem);
if (pfe->fd == fd)
{
file_close (pfe->file);
list_remove (e);
free (pfe);
lock_release (&filesys_lock);
return;
}
}
lock_release (&filesys_lock);
}

0 comments on commit 2fa247d

Please sign in to comment.