Penguin
Annotated edit history of creat(2) version 7, including all changes. View license author blame.
Rev Author # Line
1 perry 1 !!NAME
2 PerryLorier 2 creat - open and possibly create a file or device
1 perry 3 !!SYNOPSIS
7 PerryLorier 4 __#include <sys/types.h>__ /* for mode_t */
6 PerryLorier 5 __#include <sys/stat.h>__ /* for the S_* contants */
7 PerryLorier 6 __#include <fcntl.h>__ /* for creat() prototype */
2 PerryLorier 7 __int creat(const char *__''pathname''__, mode_t__ ''mode''__);__
1 perry 8 !!DESCRIPTION
9
2 PerryLorier 10 creat(2) is a special form of open(2), refer to open(2) for more information.
1 perry 11
2 PerryLorier 12 The creat(2) system call is used to convert a pathname into a file descriptor (a small, non-negative integer for use in subsequent I/O as with read(2), write(2), etc.). When the call is successful, the file descriptor returned will be the lowest file descriptor not currently open for the process. This call creates a new open file, not shared with any other process. (But shared open files may arise via the fork(2) system call.) The new file descriptor is set to remain open across exec functions (see fcntl(2)). The file offset is set to the beginning of the file.
1 perry 13
2 PerryLorier 14 creat(2) is equivalent to open(2) with ''flags'' equal to __O_CREAT|O_WRONLY|O_TRUNC__.
1 perry 15
2 PerryLorier 16 Since creat(2) doesn't take any flags, any additional flags you may wish to pass, can be modified using fcntl(2) instead.
1 perry 17
2 PerryLorier 18 The argument ''mode'' specifies the permissions to use in case a new file is created. It is modified by the process's __umask__ in the usual way: the permissions of the created file are (mode & umask).
1 perry 19
2 PerryLorier 20 The following symbolic constants are provided for ''mode'':
1 perry 21
2 PerryLorier 22 |__S_IRWXU__|00700| user (file owner) has read, write and execute permission
5 PerryLorier 23 |__S_IRUSR (S_IREAD)__|00400| user has read permission
2 PerryLorier 24 |__S_IWUSR (S_IWRITE)__|00200| user has write permission
25 |__S_IXUSR (S_IEXEC)__|00100| user has execute permission
26 |__S_IRWXG__|00070| group has read, write and execute permission
27 |__S_IRGRP__|00040| group has read permission
28 |__S_IWGRP__|00020| group has write permission
29 |__S_IXGRP__|00010| group has execute permission
30 |__S_IRWXO__|00007| others have read, write and execute permission
31 |__S_IROTH__|00004| others have read permission
32 |__S_IWOTH__|00002| others have write permisson
33 |__S_IXOTH__|00001| others have execute permission
1 perry 34
35 !!RETURN VALUE
36
2 PerryLorier 37 creat(2) returns the new file descriptor, or -1 if an error occurred (in which case, ''errno'' is set appropriately). Note that while open(2) can open device special files, but creat(2) cannot create them - use mknod(2) instead.
1 perry 38
2 PerryLorier 39 If the file is newly created, its atime, ctime, mtime fields are set to the current time, and so are the ctime and mtime fields of the parent directory. Otherwise, if the file is modified because of the O_TRUNC flag, its ctime and mtime fields are set to the current time.
1 perry 40
41 !!ERRORS
42
2 PerryLorier 43 ;[EEXIST]: ''pathname'' already exists
44 ;[EISDIR]: ''pathname'' refers to a directory and the access requested involved writing.
45 ;[EACCES]: The requested access to the file is not allowed, or one of the directories in ''pathname'' did not allow search (execute) permission, or the file did not exist yet and write access to the parent directory is not allowed.
46 ;[ENAMETOOLONG]: ''pathname'' was too long.
47 ;[ENOENT]: A directory component in ''pathname'' does not exist or is a dangling symbolic link.
48 ;[ENOTDIR]: A component used as a directory in ''pathname'' is not, in fact, a directory.
49 ;[ENXIO]: O_NONBLOCK | O_WRONLY is set, the named file is a FIFO and no process has the file open for reading. Or, the file is a device special file and no corresponding device exists.
50 ;[ENODEV]: ''pathname'' refers to a device special file and no corresponding device exists. (This is a Linux kernel bug - in this situation ENXIO must be returned.)
51 ;[EROFS]: ''pathname'' refers to a file on a read-only filesystem and write access was requested.
52 ;[ETXTBSY]: ''pathname'' refers to an executable image which is currently being executed and write access was requested.
53 ;[EFAULT]: ''pathname'' points outside your accessible address space.
54 ;[ELOOP]: Too many symbolic links were encountered in resolving ''pathname''
55 ;[ENOSPC]: ''pathname'' was to be created but the device containing ''pathname'' has no room for the new file.
56 ;[ENOMEM]: Insufficient kernel memory was available.
57 ;[EMFILE]: The process already has the maximum number of files open.
58 ;[ENFILE]: The limit on the total number of files open on the system has been reached.
1 perry 59
60 !!CONFORMING TO
4 JohnMcPherson 61 SVr4, SVID, [POSIX], X/OPEN, BSD 4.3
1 perry 62
63 !!SEE ALSO
64
2 PerryLorier 65 read(2), write(2), fcntl(2), close(2), link(2), mknod(2), mount(2), stat(2), umask(2), unlink(2), socket(2), fopen(3), fifo(4)
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.

PHP Warning

lib/blame.php:177: Warning: Invalid argument supplied for foreach() (...repeated 5 times)