#include <open.h>
fd = open_read(fn);
fd = open_write(fn);
fd = open_append(fn);
fd = open_trunc(fn);
fd = open_excl(fn);
int fd;
char *fn;
Each open function creates a new ofile
referring to a disk file named fn,
and returns a file descriptor pointing to that ofile.
If something goes wrong,
the function returns -1,
setting errno appropriately,
without allocating any resources.
open_read creates an ofile reading from the beginning of the disk file. If there is no disk file named fn, open_read returns -1 with errno set to error_noent.
open_write creates an ofile writing to the beginning of the disk file. If there is no disk file named fn, open_write returns -1 with errno set to error_noent.
open_append creates an ofile writing to the end of the disk file. If there is no disk file named fn, open_append first creates a mode-600 empty file.
open_trunc creates an ofile writing to the beginning of a new mode-644 disk file. If there is already a disk file named fn, open_trunc first truncates it to 0 bytes.
open_excl creates an ofile writing to the beginning of a new mode-644 disk file. If there is already a disk file named fn, open_excl returns -1 with errno set to error_exist, without touching the file. The entire open_excl operation is atomic.