Skip to content
Snippets Groups Projects
Commit 2d6197e6 authored by a2-stratford's avatar a2-stratford
Browse files

Minor bug fixes

parent dc5ac88c
No related branches found
No related tags found
2 merge requests!22Merge Feature/system calls,!15Alex/27 implement open system call
/*
* Opens the file called file. Returns a nonnegative integer handle called a
* "file descriptor" (fd), or -1 if the file could not be opened.
*
* Authored by Alex Stratford
*/
#include "system_calls.h"
#include "threads/interrupt.h" // Dependency for intr_frame struct
#include "filesys/file.h" // Dependency for and file struct
#include "filesys/filesys.h" // Dependency for filesys_open
void syscall_open(struct intr_frame *f) {
// pop off first int argument from interrupt frame
char* file_name = (void*)(*(int*)f->esp + 1);
// Described in filesys.h, opens the file
struct file *file = filesys_open(file_name);
if (file == NULL) { // Checking if file is empty or non-existent
f->eax = -1; // Returning a failure state
return;
}
// Described in system_calls.h, get a new file descriptor
int file_descriptor = associate_new_file_descriptor(file);
f->eax = file_descriptor; // Returning the file descriptor
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment