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 | .\" | |
b5984ffe | 5 | .\" @(#)creat.2 6.2 (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 | |
a854dd01 KM |
61 | [ENOTDIR] |
62 | A component of the path prefix is not a directory. | |
63 | .TP 15 | |
b5984ffe KM |
64 | [EINVAL] |
65 | The pathname contains a character with the high-order bit set. | |
66 | .TP 15 | |
67 | [ENAMETOOLONG] | |
68 | A component of a pathname exceeded 255 characters, | |
69 | or an entire path name exceeded 1023 characters. | |
70 | .TP 15 | |
71 | [ENOENT] | |
72 | The named file does not exist. | |
73 | .TP 15 | |
74 | [ELOOP] | |
75 | Too many symbolic links were encountered in translating the pathname. | |
76 | .TP 15 | |
a854dd01 | 77 | [EACCES] |
b5984ffe | 78 | Search permission is denied for a component of the path prefix. |
a854dd01 KM |
79 | .TP 15 |
80 | [EACCES] | |
81 | The file does not exist and the directory | |
82 | in which it is to be created is not writable. | |
83 | .TP 15 | |
84 | [EACCES] | |
85 | The file exists, but it is unwritable. | |
86 | .TP 15 | |
87 | [EISDIR] | |
88 | The file is a directory. | |
89 | .TP 15 | |
90 | [EMFILE] | |
91 | There are already too many files open. | |
92 | .TP 15 | |
93 | [EROFS] | |
94 | The named file resides on a read-only file system. | |
95 | .TP 15 | |
96 | [ENXIO] | |
97 | The file is a character special or block special file, and | |
98 | the associated device does not exist. | |
99 | .TP 15 | |
100 | [ETXTBSY] | |
101 | The file is a pure procedure (shared text) file that is being | |
102 | executed. | |
103 | .TP 15 | |
b5984ffe KM |
104 | [EIO] |
105 | An I/O error occurred while making the directory entry or allocating the inode. | |
106 | .TP 15 | |
a854dd01 KM |
107 | [EFAULT] |
108 | .I Name | |
109 | points outside the process's allocated address space. | |
110 | .TP 15 | |
a854dd01 KM |
111 | [EOPNOTSUPP] |
112 | The file was a socket (not currently implemented). | |
7d589817 | 113 | .SH "SEE ALSO" |
a854dd01 | 114 | open(2), write(2), close(2), chmod(2), umask(2) |