Open or create a file, device or other resource.
Syntax
#include <fcntl.h>
int open (const char *path, int oflag);
Parameters
-
path
Name of the file to open or create. May be absolute or relative to the current working directory.
-
oflag
Open flags for the file. Possible flags are:
O_RDONLY
,O_WRONLY
,O_RDWR
,O_CREAT
,O_TRUNC
andO_APPEND
.
Return Value
The return value is a new file descriptor if successful. Otherwise, the return value is negative and errno is set:
-
ENXIO
Incorrect instance identifier.
-
EBUSY
There is already an open file handle and the underlying device or file system does not allow sharing.
-
ENOENT
The supplied pathname could not be resolved.
-
ENOMEM
There are no free kernel or user file handles, or there is no more memory.
Remarks
The behaviour of open
depends on the file system or device specified in
path
. See the appropriate documentation for details specific to those systems.
Some device drivers may not allow easy sharing through multiple open
calls.
If the issue happens when trying to share a resource with a child process,
it is possible to get around the problem with dup2
.