Select Git revision
syscall_close.c
syscall_close.c 718 B
#include "system_calls.h"
#include "filesys/file.h" // Dependency for file_close
#include "threads/malloc.h" // Dependency for free
#include "lib/kernel/list.h" // Dependency for list_remove
int syscall_close(struct intr_frame *file_descriptor) {
// Described in system_calls.h, stores file descriptors mapped to files
struct file_map *f_map = get_file(file_descriptor);
if (f_map == NULL) // Checking if file is empty or non-existent
return -1; // Returning a failure state
// Close the file using file_closed, defined in file.h
file_close(f_map->file);
// Remove from list using list_remove, defined in list.h
list_remove(&f_map->elem);
free(f_map) // Deallocate memory using free, defined in malloc.h
}