Files
Notes
- This is 13.5 of the book (sort of)
-
int open(const char * path, int flags, int mode)
- This is a system call
- The path is the unix path, including the filename
- flags are a combination of things,
- But they must include one of :
- O_RDONLY
- O_WRONLY
- O_RDWR
- See /usr/include/bits/fcntl-linux.h
- For O_WRONLY: we might specify O_CREAT, O_TRUNC
- There are other things as well.
- mode is the permissions for the file
- But only needed if we are going to create a new file.
- SYS_OPEN = 2
- O_RDONLY = 0
- For now I only want to read, so most of these can be ignored.
- This returns a file descriptor (small positive number) or a negative on error
- This file descriptor is what we use when we call read
-
int close(int fd)
- This closes the file.
- Return 0 on success, -1 on error.
- SYS_CLOSE = 3
- We have seen the system calls read/write before.