4.3BSD beta release manual page
[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.\"
6fa8e3b5 5.\" @(#)creat.2 6.1 (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
61[EPERM]
62The argument contains a byte with the high-order bit set.
63.TP 15
64[ENOTDIR]
65A component of the path prefix is not a directory.
66.TP 15
67[EACCES]
68A needed directory does not have search permission.
69.TP 15
70[EACCES]
71The file does not exist and the directory
72in which it is to be created is not writable.
73.TP 15
74[EACCES]
75The file exists, but it is unwritable.
76.TP 15
77[EISDIR]
78The file is a directory.
79.TP 15
80[EMFILE]
81There are already too many files open.
82.TP 15
83[EROFS]
84The named file resides on a read-only file system.
85.TP 15
86[ENXIO]
87The file is a character special or block special file, and
88the associated device does not exist.
89.TP 15
90[ETXTBSY]
91The file is a pure procedure (shared text) file that is being
92executed.
93.TP 15
94[EFAULT]
95.I Name
96points outside the process's allocated address space.
97.TP 15
98[ELOOP]
99Too many symbolic links were encountered in translating the
100pathname.
101.TP 15
102[EOPNOTSUPP]
103The file was a socket (not currently implemented).
7d589817 104.SH "SEE ALSO"
a854dd01 105open(2), write(2), close(2), chmod(2), umask(2)