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