BSD 3 development
[unix-history] / usr / man / man2 / creat.2
CommitLineData
5ffa3a26
BJ
1.TH CREAT 2
2.SH NAME
3creat \- create a new file
4.SH SYNOPSIS
5.B creat(name, mode)
6.br
7.B char *name;
8.SH DESCRIPTION
9.I Creat
10creates a new file or prepares to rewrite an existing
11file called
12.I name,
13given as the address of a null-terminated string.
14If the file did not exist, it is given
15mode
16.IR mode ,
17as modified by the process's mode mask (see
18.IR umask (2)).
19Also see
20.IR chmod (2)
21for the
22construction of the
23.I mode
24argument.
25.PP
26If the file did exist, its mode and owner remain unchanged
27but it is truncated to 0 length.
28.PP
29The file is also opened for writing, and its file descriptor
30is returned.
31.PP
32The
33.I mode
34given is arbitrary; it need not allow
35writing.
36This feature is used by programs which deal with temporary
37files of fixed names.
38The creation is done with
39a mode that forbids writing.
40Then if a second
41instance of the program attempts a
42.I creat,
43an error is
44returned and the program knows that the name is unusable
45for the moment.
46.SH "SEE ALSO"
47write(2), close(2), chmod(2), umask (2)
48.SH DIAGNOSTICS
49The value \-1 is returned if:
50a needed directory is not searchable;
51the file does not exist and the directory
52in which it is to be created is not writable; the file
53does exist and is unwritable;
54the file is a directory;
55there are already too many files open.
56.SH "ASSEMBLER (PDP-11)"
57(creat = 8.)
58.br
59.B sys creat; name; mode
60.br
61(file descriptor in r0)
62.SH BUGS
63A file cannot be truncated while any process
64has pages set up by a
65.I vread
66on that file which have not been referenced.