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.
5 .\" @(#)open.2 6.4 (Berkeley) 5/14/86
7 .TH OPEN 2 "May 14, 1986"
10 open \- open a file for reading or writing, or create a new file
14 #include <sys/types.h>
17 int open(const char *\fIpath\fP, int \fIflags\fP \fR[\fP, mode_t \fImode\fP\fR]\fP)
24 for reading and/or writing, as specified by the
26 argument and returns a descriptor for that file.
29 argument may indicate the file is to be
30 created if it does not already exist (by specifying the
31 O_CREAT flag), in which case the file is created with mode
35 and modified by the process' umask value (see
39 is the address of a string of ASCII characters representing
40 a path name, terminated by a null character.
41 The flags specified are formed by
48 O_RDONLY open for reading only
49 O_WRONLY open for writing only
50 O_RDWR open for reading and writing
51 O_NONBLOCK do not block on open
52 O_APPEND append on each write
53 O_CREAT create file if it does not exist
54 O_TRUNC truncate size to 0
55 O_EXCL error if create and file exists
60 Opening a file with O_APPEND set causes each write on the file
61 to be appended to the end. If O_TRUNC is specified and the
62 file exists, the file is truncated to zero length.
63 If O_EXCL is set with O_CREAT, then if the file already
64 exists, the open returns an error. This can be used to
65 implement a simple exclusive access locking mechanism.
66 If O_EXCL is set and the last component of the pathname is
67 a symbolic link, the open will fail even if the symbolic
68 link points to a non-existent name.
69 If the O_NONBLOCK flag is specified and the open call would result
70 in the process being blocked for some reason, the open returns immediately.
72 Upon successful completion a non-negative integer termed a
73 file descriptor is returned.
74 The file pointer used to mark the current position within the
75 file is set to the beginning of the file.
77 The new descriptor is set to remain open across
82 The system imposes a limit on the number of descriptors
83 open simultaneously by one process.
85 The named file is opened unless one or more of the
89 A component of the path prefix is not a directory.
92 The path name exceeds PATH_MAX characters.
95 O_CREAT is not set and the named file does not exist.
98 A component of the path name that must exist does not exist.
101 Search permission is denied for a component of the path prefix.
104 The required permissions (for reading and/or writing)
105 are denied for the named file.
108 O_CREAT is specified,
109 the file does not exist,
110 and the directory in which it is to be created
111 does not permit writing.
114 A device to be opened for writing is physically write protected.
117 Too many symbolic links were encountered in translating the pathname.
121 The named file is a directory, and the arguments specify
122 it is to be opened for writing.
125 The named file resides on a read-only file system,
126 and the file is to be modified.
129 The system limit for open file descriptors per process has already been reached.
132 The system file table is full.
135 The named file is a character special or block
136 special file, and the device associated with this special file
140 O_CREAT is specified,
141 the file does not exist,
142 and the directory in which the entry for the new file is being placed
143 cannot be extended because there is no space left on the file
144 system containing the directory.
147 O_CREAT is specified,
148 the file does not exist,
149 and there are no free inodes on the file system on which the
150 file is being created.
154 O_CREAT is specified,
155 the file does not exist,
156 and the directory in which the entry for the new fie
157 is being placed cannot be extended because the
158 user's quota of disk blocks on the file system
159 containing the directory has been exhausted.
162 O_CREAT is specified,
163 the file does not exist,
164 and the user's quota of inodes on the file system on
165 which the file is being created has been exhausted.
169 An I/O error occurred while making the directory entry or
170 allocating the inode for O_CREAT.
174 points outside the process's allocated address space.
177 O_CREAT and O_EXCL were specified and the file exists or
180 names a symbolic link (regardless of contents of the link).