Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

chmod(2)

close(2)

dup(2)

getdtablesize(2)

lseek(2)

read(2)

write(2)

umask(2)

unlink(2)



OPEN(2)                 COMMAND REFERENCE                 OPEN(2)



NAME
     open - open a file for reading or writing, or create a new
     file

SYNOPSIS
     #include <sys/file.h>

     fd = open(path, flags, mode)
     int fd;
     char *path;
     int flags, mode;

DESCRIPTION
     Open opens the file named by path as specified by the flags
     argument and returns a descriptor for that file in fd.

     The flags argument may indicate the file is to be created if
     it does not already exist (by specifying the O_CREAT flag),
     in which case the file is created with mode mode as
     described in chmod(2) and modified by the process' umask
     value (see umask(2)).

     Path is a null-terminated pathname (the address of a string
     of ASCII characters representing a pathname, terminated by a
     null character).  Flags is constructed by or'ing the
     following values, defined in <sys/file.h>:

     O_RDONLY
         Open for reading only.

     O_WRONLY
         Open for writing only.

     O_RDWR
         Open for reading and writing.

     O_NDELAY
         Do not block on open.

         If the open call would result in the process being
         blocked for some reason (e.g., waiting for carrier on a
         dialup line), the open returns immediately.

     O_APPEND
         Append on each write.

         If set, the file pointer will be set to the end of the
         file prior to each write.

     O_CREAT
         Create file if it does not exist.




Printed 10/17/86                                                1





OPEN(2)                 COMMAND REFERENCE                 OPEN(2)



     O_TRUNC
         Truncate size to 0.

         If the file exists, it is truncated to zero length.

     O_EXCL
         Error if create and file exists.

         If O_EXCL and O_CREAT are set, open will fail if the
         file exists.

     Upon successful completion a non-negative integer fd, termed
     a file descriptor, is returned.  The file pointer used to
     mark the current position within the file is set to the
     beginning of the file.

     The new descriptor is set to remain open across execve
     system calls; see close(2).

     There is a limit on the number of file descriptors a process
     may have open simultaneously.  This number is NOFILE,
     defined in <sys/max.h>.  The getdtablesize(2) call returns
     the current value of NOFILE.

DIAGNOSTICS
     The named file is opened unless one or more of the following
     are true:

     [ENAMETOOLONG]
         The argument path is too long.

     [ENOASCII]
         The pathname contains a character with the high-order
         bit set.

     [ENOTDIR]
         A component of the path prefix is not a directory.

     [ENOENT]
         O_CREAT is not set and the named file does not exist.

     [EACCES]
         A component of the path prefix denies search permission.

     [EACCES]
         The required permissions (for reading and/or writing)
         are denied for the named flag.  If the file is located
         on a remote host, this error code will be returned if
         the local host name and local user name does not appear
         in /usr/lib/dfs/access on the remote machine.  See
         access(dfs)(5n).




Printed 10/17/86                                                2





OPEN(2)                 COMMAND REFERENCE                 OPEN(2)



     [EISDIR]
         The named file is a directory, and the arguments specify
         it is to be opened for writing.

     [EROFS]
         The named file resides on a read-only file system, and
         the file is to be modified.

     [EMFILE]
         NOFILE files are currently open (see getdtablesize(2)).

     [ENXIO]
         The named file is a character special or block special
         file, and the device associated with this special file
         does not exist.

     [ETXTBSY]
         The file is a pure procedure (shared text) file that is
         being executed and the open call requests write access.

     [EFAULT]
         Path points outside the process's allocated address
         space.

     [ELOOP]
         Too many symbolic links were encountered in translating
         the pathname.

     [EEXIST]
         O_EXCL is specified and the file exists.

     [ENOSPC]
         O_CREAT is specified, and the file system is out of
         inodes.

     [ENOSPC]
         The directory in which the entry for the new file is
         being placed cannot be extended because there is no
         space left on the file system containing the directory,
         the file does not exist and O_CREAT is specified.

     [ENFILE]
         O_CREAT is specified, and the system inode table is
         full.

     [EIO]
         An I/O error occurred while reading from or writing to
         the file system.

     [ENXIO]
         The O_NDELAY flag is given, and the file is a
         communications device on which their is no carrier



Printed 10/17/86                                                3





OPEN(2)                 COMMAND REFERENCE                 OPEN(2)



         present.

     [EBUSY]
         An exclusively-opened port is already opened.

     [EOPNOTSUPP]
         An attempt is made to open a socket (not currently
         implemented).

     [EDFSNOSUCHHOST]
         The pathname referenced a remote host, but when we
         broadcast a request for its address, no host responded.

RETURN VALUE
     If no error occurred, open returns the file descriptor in
     fd. Otherwise, -1 is returned and errno is set to indicate
     the error.

SEE ALSO
     chmod(2), close(2), dup(2), getdtablesize(2), lseek(2),
     read(2), write(2), umask(2), unlink(2).


































Printed 10/17/86                                                4



%%index%%
na:72,104;
sy:176,616;
de:792,1400;2336,838;
di:3174,960;4278,1607;6029,338;
rv:6367,245;
se:6612,308;
%%index%%000000000136

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026