fd_open
fd_open — opens a file or device and assigns it a file descriptor.
Syntax
fd_open (name, mode)
Arguments
- name
- The name of a file, as a
string.
- mode
- The mode for opening the
file.
Returns
A non-negative integer representing the lowest numbered unused
file descriptor if successful. If an error occurs, the
function returns -1 and sets the errno.
Description
This function opens a file for reading and/or writing, and
assigns it a file descriptor which is used as an argument by
other functions such as fd_read and
fd_write.
The file that is opened could be a regular file, a directory, or
a block or character device. Legal mode
values are:
- O_RDONLY Read-only mode
- O_WRONLY Write-only mode
- O_RDWR Read-Write mode
Any combination of the following flags may be bitwise
OR-ed with the open mode to modify how the file is
accessed:
- O_APPEND Append (writes guaranteed at the end)
- O_CREAT Opens with file create
- O_EXCL Exclusive open
- O_NOCTTY Don't assign a controlling terminal
- O_NONBLOCK Non-blocking I/O
- O_TRUNC Open with truncation
- O_DSYNC Data integrity synch
- O_SYNC File integrity synch
- O_TEMP Temporary file, don't put to disk
- O_CACHE Cache sequential files too
If an error occurs -1 is returned and errno is set to one of the following:
- EACCES Search
permission denied on a portion of the path prefix,
or the file exists and the permissions required to
open the file in the given mode so not
exist.
- EBADFSYS The file or
the path prefix to the file was found to be
corrupted
- EBUSY The file is
already open for writing.
- EEXIST O_CREAT and
O_EXCL are set and the named file exists
- EINTR The function was interrupted by a signal
- EISDIR The named file is a directory
- EMFILE Too many file
descriptors are currently in use by this
process
- ENAMETOOLONG The
length of the path to the file is too long.
- ENFILE Too many files are currently open on the system
- ENOENT O_CREAT is not
set and the file does not exist
- ENOSPC The directory
or file system which would create the new file
cannot be extended
- ENOTDIR A component
of the path to the file is not a directory
- ENXIO O_NONBLOCK is
set, the file is a FIFO, O_WRONLY is set, and no
process has the file open for reading
- EROFS The named file
resides on a read-only file system.
Example
Gamma> require_lisp("const/filesys");
"/usr/cogent/lib/const/filesys.lsp"
Gamma> ptr = fd_open("/fd/ttyp8",O_WRONLY);
4
Gamma> fd_write(ptr,"\nhello\n");
7