|
|
1.1 ! root 1: .\" Copyright (c) 1980 Regents of the University of California. ! 2: .\" All rights reserved. The Berkeley software License Agreement ! 3: .\" specifies the terms and conditions for redistribution. ! 4: .\" ! 5: .\" @(#)open.2 6.5 (Berkeley) 8/12/88 ! 6: .\" ! 7: .TH OPEN 2 "August 12, 1988" ! 8: .UC 4 ! 9: .SH NAME ! 10: open \- open a file for reading or writing, or create a new file ! 11: .SH SYNOPSIS ! 12: .nf ! 13: .ft B ! 14: #include <sys/file.h> ! 15: .PP ! 16: .ft B ! 17: open(path, flags, mode) ! 18: char *path; ! 19: int flags, mode; ! 20: .fi ! 21: .SH DESCRIPTION ! 22: .I Open ! 23: opens the file ! 24: .I path ! 25: for reading and/or writing, as specified by the ! 26: .I flags ! 27: argument and returns a descriptor for that file. ! 28: The ! 29: .I flags ! 30: argument may indicate the file is to be ! 31: created if it does not already exist (by specifying the ! 32: O_CREAT flag), in which case the file is created with mode ! 33: .I mode ! 34: as described in ! 35: .IR chmod (2) ! 36: and modified by the process' umask value (see ! 37: .IR umask (2)). ! 38: .PP ! 39: .I Path ! 40: is the address of a string of ASCII characters representing ! 41: a path name, terminated by a null character. ! 42: The flags specified are formed by ! 43: .IR or 'ing ! 44: the following values ! 45: .PP ! 46: .RS ! 47: O_RDONLY open for reading only ! 48: O_WRONLY open for writing only ! 49: O_RDWR open for reading and writing ! 50: O_NDELAY do not block on open ! 51: O_APPEND append on each write ! 52: O_CREAT create file if it does not exist ! 53: O_TRUNC truncate size to 0 ! 54: O_EXCL error if create and file exists ! 55: .RE ! 56: .PP ! 57: Opening a file with O_APPEND set causes each write on the file ! 58: to be appended to the end. If O_TRUNC is specified and the ! 59: file exists, the file is truncated to zero length. ! 60: If O_EXCL is set with O_CREAT, then if the file already ! 61: exists, the open returns an error. This can be used to ! 62: implement a simple exclusive access locking mechanism. ! 63: If O_EXCL is set and the last component of the pathname is ! 64: a symbolic link, the open will fail even if the symbolic ! 65: link points to a non-existent name. ! 66: If the O_NDELAY flag is specified and the open call would result ! 67: in the process being blocked for some reason (e.g. waiting for ! 68: carrier on a dialup line), the open returns immediately. ! 69: The first time the process attempts to perform i/o on the open ! 70: file it will block (not currently implemented). ! 71: .PP ! 72: If successful, \fIopen\fP returns a non-negative integer, termed a ! 73: file descriptor. It returns -1 on failure. ! 74: The file pointer used to mark the current position within the ! 75: file is set to the beginning of the file. ! 76: .PP ! 77: The new descriptor is set to remain open across ! 78: .IR execve ! 79: system calls; see ! 80: .IR close (2). ! 81: .PP ! 82: The system imposes a limit on the number of file descriptors ! 83: open simultaneously by one process. ! 84: .IR Getdtablesize (2) ! 85: returns the current system limit. ! 86: .SH "ERRORS ! 87: The named file is opened unless one or more of the ! 88: following are true: ! 89: .TP 15 ! 90: [ENOTDIR] ! 91: A component of the path prefix is not a directory. ! 92: .TP 15 ! 93: [EINVAL] ! 94: The pathname contains a character with the high-order bit set. ! 95: .TP 15 ! 96: [ENAMETOOLONG] ! 97: A component of a pathname exceeded 255 characters, ! 98: or an entire path name exceeded 1023 characters. ! 99: .TP 15 ! 100: [ENOENT] ! 101: O_CREAT is not set and the named file does not exist. ! 102: .TP 15 ! 103: [ENOENT] ! 104: A component of the path name that must exist does not exist. ! 105: .TP 15 ! 106: [EACCES] ! 107: Search permission is denied for a component of the path prefix. ! 108: .TP 15 ! 109: [EACCES] ! 110: The required permissions (for reading and/or writing) ! 111: are denied for the named flag. ! 112: .TP 15 ! 113: [EACCES] ! 114: O_CREAT is specified, ! 115: the file does not exist, ! 116: and the directory in which it is to be created ! 117: does not permit writing. ! 118: .TP 15 ! 119: [ELOOP] ! 120: Too many symbolic links were encountered in translating the pathname. ! 121: .TP 15 ! 122: [EISDIR] ! 123: The named file is a directory, and the arguments specify ! 124: it is to be opened for writting. ! 125: .TP 15 ! 126: [EROFS] ! 127: The named file resides on a read-only file system, ! 128: and the file is to be modified. ! 129: .TP 15 ! 130: [EMFILE] ! 131: The system limit for open file descriptors per process has already been reached. ! 132: .TP 15 ! 133: [ENFILE] ! 134: The system file table is full. ! 135: .TP 15 ! 136: [ENXIO] ! 137: The named file is a character special or block ! 138: special file, and the device associated with this special file ! 139: does not exist. ! 140: .TP 15 ! 141: [ENOSPC] ! 142: O_CREAT is specified, ! 143: the file does not exist, ! 144: and the directory in which the entry for the new file is being placed ! 145: cannot be extended because there is no space left on the file ! 146: system containing the directory. ! 147: .TP 15 ! 148: [ENOSPC] ! 149: O_CREAT is specified, ! 150: the file does not exist, ! 151: and there are no free inodes on the file system on which the ! 152: file is being created. ! 153: .TP 15 ! 154: [EDQUOT] ! 155: O_CREAT is specified, ! 156: the file does not exist, ! 157: and the directory in which the entry for the new fie ! 158: is being placed cannot be extended because the ! 159: user's quota of disk blocks on the file system ! 160: containing the directory has been exhausted. ! 161: .TP 15 ! 162: [EDQUOT] ! 163: O_CREAT is specified, ! 164: the file does not exist, ! 165: and the user's quota of inodes on the file system on ! 166: which the file is being created has been exhausted. ! 167: .TP 15 ! 168: [EIO] ! 169: An I/O error occurred while making the directory entry or ! 170: allocating the inode for O_CREAT. ! 171: .TP 15 ! 172: [ETXTBSY] ! 173: The file is a pure procedure (shared text) file that is being ! 174: executed and the \fIopen\fP call requests write access. ! 175: .TP 15 ! 176: [EFAULT] ! 177: .I Path ! 178: points outside the process's allocated address space. ! 179: .TP 15 ! 180: [EEXIST] ! 181: O_CREAT and O_EXCL were specified and the file exists. ! 182: .TP 15 ! 183: [EOPNOTSUPP] ! 184: An attempt was made to open a socket (not currently implemented). ! 185: .SH "SEE ALSO" ! 186: chmod(2), close(2), dup(2), getdtablesize(2), ! 187: lseek(2), read(2), write(2), umask(2)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.