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