RTEMS Logo

RTEMS 4.10.2 On-Line Library


Files and Directories Manager open - Opens a file

PREV UP NEXT Bookshelf RTEMS POSIX API User's Guide

4.4.10: open - Opens a file

CALLING SEQUENCE:

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

int open(
  const char *path,
  int         oflag,
  mode_t      mode
);

STATUS CODES:

EACCES
Search permission is denied for a directory in a file's path prefix.
EEXIST
The named file already exists.
EINTR
Function was interrupted by a signal.
EISDIR
Attempt to open a directory for writing or to rename a file to be a directory.
EMFILE
Too many file descriptors are in use by this process.
ENAMETOOLONG
Length of a filename string exceeds PATH_MAX and _POSIX_NO_TRUNC is in effect.
ENFILE
Too many files are currently open in the system.
ENOENT
A file or directory does not exist.
ENOSPC
No space left on disk.
ENOTDIR
A component of the specified pathname was not a directory when a directory was expected.
ENXIO
No such device. This error may also occur when a device is not ready, for example, a tape drive is off-line.
EROFS
Read-only file system.

DESCRIPTION:

The open function establishes a connection between a file and a file descriptor. The file descriptor is a small integer that is used by I/O functions to reference the file. The path argument points to the pathname for the file.

The oflag argument is the bitwise inclusive OR of the values of symbolic constants. The programmer must specify exactly one of the following three symbols:

O_RDONLY
Open for reading only.
O_WRONLY
Open for writing only.
O_RDWR
Open for reading and writing.

Any combination of the following symbols may also be used.

O_APPEND
Set the file offset to the end-of-file prior to each write.
O_CREAT
If the file does not exist, allow it to be created. This flag indicates that the mode argument is present in the call to open.
O_EXCL
This flag may be used only if O_CREAT is also set. It causes the call to open to fail if the file already exists.
O_NOCTTY
If path identifies a terminal, this flag prevents that teminal from becoming the controlling terminal for thi9s process. See Chapter 8 for a description of terminal I/O.
O_NONBLOCK
Do no wait for the device or file to be ready or available. After the file is open, the read and write calls return immediately. If the process would be delayed in the read or write opermation, -1 is returned and errno is set to EAGAIN instead of blocking the caller.
O_TRUNC
This flag should be used only on ordinary files opened for writing. It causes the file to be tuncated to zero length..

Upon successful completion, open returns a non-negative file descriptor.

NOTES:

NONE


PREV UP NEXT Bookshelf RTEMS POSIX API User's Guide

Copyright © 1988-2008 OAR Corporation