BSD 4_2 development
[unix-history] / usr / man / man2 / creat.2
CommitLineData
df930a0c
C
1.TH CREAT 2 "2 July 1983"
2.UC 4
3.SH NAME
4creat \- create a new file
5.SH SYNOPSIS
6.nf
7.B creat(name, mode)
8.B char *name;
9.fi
10.SH DESCRIPTION
11.B "This interface is obsoleted by open(2).
12.PP
13.I Creat
14creates a new file or prepares to rewrite an existing
15file called
16.IR name ,
17given as the address of a null-terminated string.
18If the file did not exist, it is given
19mode
20.IR mode ,
21as modified by the process's mode mask (see
22.IR umask (2)).
23Also see
24.IR chmod (2)
25for the
26construction of the
27.I mode
28argument.
29.PP
30If the file did exist, its mode and owner remain unchanged
31but it is truncated to 0 length.
32.PP
33The file is also opened for writing, and its file descriptor
34is returned.
35.SH NOTES
36The
37.I mode
38given is arbitrary; it need not allow
39writing.
40This feature has been used in the past by
41programs to construct a simple exclusive locking
42mechanism. It is replaced by the O_EXCL open
43mode, or
44.IR flock (2)
45facilitity.
46.SH "RETURN VALUE
47The value \-1 is returned if an error occurs. Otherwise,
48the call returns a non-negative descriptor which only permits
49writing.
50.SH ERRORS
51.I Creat
52will fail and the file will not be created or truncated
53if one of the following occur:
54.TP 15
55[EPERM]
56The argument contains a byte with the high-order bit set.
57.TP 15
58[ENOTDIR]
59A component of the path prefix is not a directory.
60.TP 15
61[EACCES]
62A needed directory does not have search permission.
63.TP 15
64[EACCES]
65The file does not exist and the directory
66in which it is to be created is not writable.
67.TP 15
68[EACCES]
69The file exists, but it is unwritable.
70.TP 15
71[EISDIR]
72The file is a directory.
73.TP 15
74[EMFILE]
75There are already too many files open.
76.TP 15
77[EROFS]
78The named file resides on a read-only file system.
79.TP 15
80[ENXIO]
81The file is a character special or block special file, and
82the associated device does not exist.
83.TP 15
84[ETXTBSY]
85The file is a pure procedure (shared text) file that is being
86executed.
87.TP 15
88[EFAULT]
89.I Name
90points outside the process's allocated address space.
91.TP 15
92[ELOOP]
93Too many symbolic links were encountered in translating the
94pathname.
95.TP 15
96[EOPNOTSUPP]
97The file was a socket (not currently implemented).
98.SH "SEE ALSO"
99open(2), write(2), close(2), chmod(2), umask(2)