We've made sure that the pathname is valid, and we've resolved any symbolic links that we needed to.
Now we need to figure out the mode flags.
There are a few combinations that we need to take care of:
- If both the O_CREAT and O_EXCL flags are set, then the target must not exist
(else we error-out with EEXIST).
- If the flag O_CREAT is set, the target may or may not exist; we might be creating it.
- If the flag O_CREAT is not set, then the target must exist (else we error-out with
ENOENT).
- If the flag O_TRUNC and either O_RDWR or O_WRONLY are set,
then we need to trim the target's length to zero and wipe out its data.
This may involve creating or truncating the target, or returning error indications.
We'll see this in the code walkthrough below.