A file operation typically uses 5 functions:
Open, read, write, Lseek, close
For the kernel, all open files are referenced by a file descriptor (non-negative integer). When an existing file is opened or a new file is created, the kernel returns a file descriptor to the process.
When reading and writing a file, use open or creat to return a file descriptor to identify the file and pass its arguments to read or write.
The UNIX system shell uses file descriptors 0, 1, and 2, respectively, associated with the process's standard input, standard output, and standard error output.
In a POSIX-compliant application, the magic number 0, 1, and 2 should be replaced with symbolic constants Stdin_fileno, Stdout_fileno, Stderr_fileno, defined in the header file <unistd.h>.
Open function
Oflag constants include: O_rdonly, O_wronly, O_rdwr, O_append, O_creat, and so on.
Lseek function
Sets the current file offset. The whence value can be
File I/O