Open, Part 2
Objectives
We would like to :
- Understand more of the options when opening a file.
Notes
- The man page/book lists many different options we can use when opening a file.
- We need to look at these to get the flavor of operation.
- I will look at a few
-
O_APPEND
always write to the end of the file
- This is important later. (Just like O_RDWR)
-
O_CLOEXEC
close on exec
- We will discuss this one later as well.
-
O_DIRECT
try not to cache/buffer this file
- Used with
O_SYNC
to require synchronous I/O
- Otherwise advisory to the OS
-
O_EXCL
- When creating a file, fail if the pathname already exists.
- This is to force creation of a new file.
-
O_TRUNC
- If the file exists, truncate to length 0.
-
O_TMPFILE
- Construct a tempory file
- This will be removed when the last file descriptor is closed
- In this case, pathname specifies a directory where the file will be created
- Must be opened with O_RDWR or O_WRONLY
- There is a discussion on how the file can be preserved if needed.
- There are more, but not now.
-
int creat(const char *pathname, mode_t mode);
- A convience routine for calling open with O_CREAT|O_WRONLY|O_TRUNC