INtime SDK Help

Opens a file and prepares it for subsequent reading or writing.

#include <fcntl.h>
#include <sys/stat.h>
#include <io.h>

int open(const char *filename, int oflag [, int pmode]);


Filename of file to open.
Open mode (type of operations allowed) as an integer expression formed from one or more of the manifest constants defined in fcntl.h. Oflag must contain either O_RDONLY, O_RDWR, or O_WRONLY. Optional flags include O_CREAT, O_BINARY, O_APPEND, O_TRUNC and O_EXCL. Combine two or more of the constants with the bitwise-OR operator (|). There is no default.
oflag Description
O_BINARY Open the file in binary mode. Without this flag the file is opened in ASCII mode.
O_TEXT Open the file in ASCII mode (the default mode). In this mode end-of-line sequences are translated and the end-of-file character CTRL-Z is recognized.
O_WTEXT Open the file in wide-character text mode. In this mode end-of-line sequences are translated and the end-of-file character CTRL-Z is recognized.
O_CREAT If this flag is specified an attempt is made to create the file. If the file does not exist then it is created. If the file does exist then the call fails unless the O_TRUNC falg is also given.
O_TRUNC The file is truncated after opening. If combined with O_CREAT then an existing file may be opened and then truncated.
O_APPEND The file pointer is moved to the end of the file after opening.
O_EXCL The file is opened with exclusive (i.e. not shared) access.
Permission mode, required when specifying O_CREAT. Ignored if the file exists. Specifies the file's ownership and access rights, which are set when the new file is closed for the first time. Contains one or more of the manifest constants described in chmod.


The open function applies the default file-permission mask set with umask to pmode before setting the permissions.

By default, this function creates files that all threads can share. If O_EXCL is OR-ed with pmode, the file is opened with share-with-none permission.

Return Values

A file descriptor for the opened file.
-1 and the function sets errno to one of these values:
EACCES Given pathname is a directory; or an attempt was made to open a read-only file for writing; or a sharing violation occurred (the file's share mode does not allow the specified operations).
EEXIST The O_CREAT and O_EXCL flags are specified, but the named file already exists.
EINVAL An invalid oflag or pmode argument was given.
EMFILE No more file descriptors available (too many open files).
ENOENT File or pathname not found.


Versions Defined in Include Link to
INtime 3.0
INtime 6.0 (for wide-character support)
intime/rt/include/fcntl.h (for oflag definitions)
See Also