1CREAT(P) POSIX Programmer's Manual CREAT(P)
2
3
4
6 creat - create a new file or rewrite an existing one
7
9 #include <sys/stat.h>
10 #include <fcntl.h>
11
12 int creat(const char *path, mode_t mode);
13
14
16 The function call:
17
18
19 creat(path, mode)
20
21 shall be equivalent to:
22
23
24 open(path, O_WRONLY|O_CREAT|O_TRUNC, mode)
25
27 Refer to open() .
28
30 Refer to open() .
31
32 The following sections are informative.
33
35 Creating a File
36 The following example creates the file /tmp/file with read and write
37 permissions for the file owner and read permission for group and oth‐
38 ers. The resulting file descriptor is assigned to the fd variable.
39
40
41 #include <fcntl.h>
42 ...
43 int fd;
44 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
45 char *filename = "/tmp/file";
46 ...
47 fd = creat(filename, mode);
48 ...
49
51 None.
52
54 The creat() function is redundant. Its services are also provided by
55 the open() function. It has been included primarily for historical pur‐
56 poses since many existing applications depend on it. It is best consid‐
57 ered a part of the C binding rather than a function that should be pro‐
58 vided in other languages.
59
61 None.
62
64 open() , the Base Definitions volume of IEEE Std 1003.1-2001,
65 <fcntl.h>, <sys/stat.h>, <sys/types.h>
66
68 Portions of this text are reprinted and reproduced in electronic form
69 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
70 -- Portable Operating System Interface (POSIX), The Open Group Base
71 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
72 Electrical and Electronics Engineers, Inc and The Open Group. In the
73 event of any discrepancy between this version and the original IEEE and
74 The Open Group Standard, the original IEEE and The Open Group Standard
75 is the referee document. The original Standard can be obtained online
76 at http://www.opengroup.org/unix/online.html .
77
78
79
80IEEE/The Open Group 2003 CREAT(P)