Skip to content
Snippets Groups Projects
Select Git revision
  • 99b765c8e45d564bb14c3fbed4e49881bbd2d9f2
  • master default protected
  • backup/alex-27
  • Test/file-system
  • Test/syscall-test-branch
  • josh/miscellaneous-improvements
  • alex/exit-system-call
  • josh/backup-alex-6
  • backup/Alex
9 results

syscall_close.c

Blame
  • Alex Stratford's avatar
    a2-stratford authored
    Edited system_calls.h to add dependency
    99b765c8
    History
    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
    }