SLAU132Y September 2004 – June 2021
Open File for I/O
#include <file.h>
int open (const char * path , unsigned flags , int file_descriptor );
The open function opens the file specified by path and prepares it for I/O.
O_RDONLY (0x0000) /* open for reading */
O_WRONLY (0x0001) /* open for writing */
O_RDWR (0x0002) /* open for read & write */
O_APPEND (0x0008) /* append on each write */
O_CREAT (0x0200) /* open with file create */
O_TRUNC (0x0400) /* open with truncation */
O_BINARY (0x8000) /* open in binary mode */
Low-level I/O routines allow or disallow some operations depending on the flags used when the file was opened. Some flags may not be meaningful for some devices, depending on how the device implements files.
The next available file descriptor is assigned to each new file opened.
The function returns one of the following values:
non-negative file descriptor | if successful |
-1 | on failure |