Penguin

Differences between current version and predecessor to the previous major change of creat(2).

Other diffs: Previous Revision, Previous Author, or view the Annotated Edit History

Newer page: version 7 Last edited on Sunday, November 3, 2002 2:31:40 pm by PerryLorier
Older page: version 1 Last edited on Tuesday, June 4, 2002 12:23:40 am by perry Revert
@@ -1,433 +1,65 @@
-OPEN  
-!!!OPEN  
-NAME  
-SYNOPSIS  
-DESCRIPTION  
-RETURN VALUE  
-ERRORS  
-CONFORMING TO  
-RESTRICTIONS  
-SEE ALSO  
-----  
 !!NAME 
-  
-  
-open, creat - open and possibly create a file or device 
+creat - open and possibly create a file or device 
 !!SYNOPSIS 
-  
-  
- __#include  
- __''pathname'' __, int __ ''flags'' __);  
-int open(const char * __''pathname'' __, int __ ''flags''__, mode_t__ ''mode''__);  
- int creat(const char *__''pathname''__, mode_t__ ''mode''__);  
- __ 
+ __#include <sys/types.h> __ /* for mode _t */  
+ __#include <sys/stat.h> __ /* for the S _* contants */  
+ __#include <fcntl.h> __ /* for creat() prototype */  
+ __int creat(const char *__''pathname''__, mode_t__ ''mode''__);__ 
 !!DESCRIPTION 
  
+creat(2) is a special form of open(2), refer to open(2) for more information.  
  
-The __open ()__ 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__ , __ write__ ,  
- 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. 
+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. 
  
+creat(2) is equivalent to open(2) with ''flags'' equal to __O_CREAT|O_WRONLY|O_TRUNC__.  
  
-The parameter ' 'flags'' is one of __O_RDONLY__ ,  
-__O_WRONLY__ or __O_RDWR__ which request opening the  
-file read-only , write-only or read/write, respectively,  
-bitwise-''or'''d with zero or more of the  
-following:  
+Since creat(2) doesn 't take any flags, any additional flags you may wish to pass , can be modified using fcntl(2) instead.  
  
+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).  
  
-__O_CREAT__  
+The following symbolic constants are provided for ''mode'':  
  
+|__S_IRWXU__|00700| user (file owner) has read, write and execute permission  
+|__S_IRUSR (S_IREAD)__|00400| user has read permission  
+|__S_IWUSR (S_IWRITE)__|00200| user has write permission  
+|__S_IXUSR (S_IEXEC)__|00100| user has execute permission  
+|__S_IRWXG__|00070| group has read, write and execute permission  
+|__S_IRGRP__|00040| group has read permission  
+|__S_IWGRP__|00020| group has write permission  
+|__S_IXGRP__|00010| group has execute permission  
+|__S_IRWXO__|00007| others have read, write and execute permission  
+|__S_IROTH__|00004| others have read permission  
+|__S_IWOTH__|00002| others have write permisson  
+|__S_IXOTH__|00001| others have execute permission  
  
-If the file does not exist it will be created. The owner  
-(user ID) of the file is set to the effective user ID of the  
-process. The group ownership (group ID) is set either to the  
-effective group ID of the process or to the group ID of the  
-parent directory (depending on filesystem type and mount  
-options, and the mode of the parent directory, see, e.g.,  
-the mount options ''bsdgroups'' and ''sysvgroups'' of  
-the ext2 filesystem, as described in  
-mount(8)).  
-  
-  
-__O_EXCL__  
-  
-  
-When used with __O_CREAT__, if the file already exists it  
-is an error and the __open__ will fail. In this context,  
-a symbolic link exists, regardless of where its points to.  
-__O_EXCL__ is broken on NFS file systems, programs which  
-rely on it for performing locking tasks will contain a race  
-condition. The solution for performing atomic file locking  
-using a lockfile is to create a unique file on the same fs  
-(e.g., incorporating hostname and pid), use link(2)  
-to make a link to the lockfile. If __link()__ returns 0,  
-the lock is successful. Otherwise, use stat(2) on the  
-unique file to check if its link count has increased to 2,  
-in which case the lock is also successful.  
-  
-  
-__O_NOCTTY__  
-  
-  
-If ''pathname'' refers to a terminal device -- see  
-tty(4) -- it will not become the process's  
-controlling terminal even if the process does not have  
-one.  
-  
-  
-__O_TRUNC__  
-  
-  
-If the file already exists and is a regular file and the  
-open mode allows writing (i.e., is O_RDWR or O_WRONLY) it  
-will be truncated to length 0. If the file is a FIFO or  
-terminal device file, the O_TRUNC flag is ignored. Otherwise  
-the effect of O_TRUNC is unspecified. (On many Linux  
-versions it will be ignored; on other versions it will  
-return an error.)  
-  
-  
-__O_APPEND__  
-  
-  
-The file is opened in append mode. Before each __write__,  
-the file pointer is positioned at the end of the file, as if  
-with __lseek__. __O_APPEND__ may lead to corrupted  
-files on NFS file systems if more than one process appends  
-data to a file at once. This is because NFS does not support  
-appending to a file, so the client kernel has to simulate  
-it, which can't be done without a race  
-condition.  
-  
-  
-__O_NONBLOCK__ or __O_NDELAY__  
-  
-  
-When possible, the file is opened in non-blocking mode.  
-Neither the __open__ nor any subsequent operations on the  
-file descriptor which is returned will cause the calling  
-process to wait. For the handling of FIFOs (named pipes),  
-see also fifo(4). This mode need not have any effect  
-on files other than FIFOs.  
-  
-  
-__O_SYNC__  
-  
-  
-The file is opened for synchronous I/O. Any __write__s on  
-the resulting file descriptor will block the calling process  
-until the data has been physically written to the underlying  
-hardware. ''See RESTRICTIONS below,  
-though.''  
-  
-  
-__O_NOFOLLOW__  
-  
-  
-If ''pathname'' is a symbolic link, then the open fails.  
-This is a FreeBSD extension, which was added to Linux in  
-version 2.1.126. Symbolic links in earlier components of the  
-pathname will still be followed. The headers from glibc  
-2.0.100 and later include a definition of this flag;  
-''kernels before 2.1.126 will ignore it if  
-used''.  
-  
-  
-__O_DIRECTORY__  
-  
-  
-If ''pathname'' is not a directory, cause the open to  
-fail. This flag is Linux-specific, and was added in kernel  
-version 2.1.126, to avoid denial-of-service problems if  
-opendir(3) is called on a FIFO or tape device, but  
-should not be used outside of the implementation of  
-__opendir__.  
-  
-  
-__O_LARGEFILE__  
-  
-  
-On 32-bit systems that support the Large Files System, allow  
-files whose sizes cannot be represented in 31 bits to be  
-opened.  
-  
-  
-Some of these optional flags can be altered using  
-__fcntl__ after the file has been opened.  
-  
-  
-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 __. Note that this  
-mode only applies to future accesses of the newly created  
-file; the __open__ call that creates a read-only file may  
-well return a read/write file descriptor.  
-  
-  
-The following symbolic constants are provided for  
-''mode'':  
-  
-  
-__S_IRWXU__  
-  
-  
-00700 user (file owner) has read, write and execute  
-permission  
-  
-  
-__S_IRUSR (S_IREAD)__  
-  
-  
-00400 user has read permission  
-  
-  
-__S_IWUSR (S_IWRITE)__  
-  
-  
-00200 user has write permission  
-  
-  
-__S_IXUSR (S_IEXEC)__  
-  
-  
-00100 user has execute permission  
-  
-  
-__S_IRWXG__  
-  
-  
-00070 group has read, write and execute  
-permission  
-  
-  
-__S_IRGRP__  
-  
-  
-00040 group has read permission  
-  
-  
-__S_IWGRP__  
-  
-  
-00020 group has write permission  
-  
-  
-__S_IXGRP__  
-  
-  
-00010 group has execute permission  
-  
-  
-__S_IRWXO__  
-  
-  
-00007 others have read, write and execute  
-permission  
-  
-  
-__S_IROTH__  
-  
-  
-00004 others have read permission  
-  
-  
-__S_IWOTH__  
-  
-  
-00002 others have write permisson  
-  
-  
-__S_IXOTH__  
-  
-  
-00001 others have execute permission  
-  
-  
-''mode'' should always be specified when __O_CREAT__  
-is in the ''flags'', and is ignored  
-otherwise.  
-  
-  
-__creat__ is equivalent to __open__ with ''flags''  
-equal to __O_CREAT|O_WRONLY|O_TRUNC__.  
 !!RETURN VALUE 
  
+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.  
  
-__open__ and __creat__ return the new file descriptor ,  
-or -1 if an error occurred (in which case , ''errno'' is  
- set appropriately) . Note that __open_ _ can open device  
-special files , but __creat__ cannot create them - use  
-mknod(2) instead
+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
  
-  
-On NFS file systems with UID mapping enabled, __open__  
-may return a file descriptor but e.g. read(2)  
-requests are denied with __EACCES__. This is because the  
-client performs __open__ by checking the permissions, but  
-UID mapping is performed by the server upon read and write  
-requests.  
-  
-  
-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.  
 !!ERRORS 
  
+;[EEXIST]: ''pathname'' already exists  
+;[EISDIR]: ''pathname'' refers to a directory and the access requested involved writing.  
+;[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.  
+;[ENAMETOOLONG]: ''pathname'' was too long.  
+;[ENOENT]: A directory component in ''pathname'' does not exist or is a dangling symbolic link.  
+;[ENOTDIR]: A component used as a directory in ''pathname'' is not, in fact, a directory.  
+;[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.  
+;[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.)  
+;[EROFS]: ''pathname'' refers to a file on a read-only filesystem and write access was requested.  
+;[ETXTBSY]: ''pathname'' refers to an executable image which is currently being executed and write access was requested.  
+;[EFAULT]: ''pathname'' points outside your accessible address space.  
+;[ELOOP]: Too many symbolic links were encountered in resolving ''pathname''  
+;[ENOSPC]: ''pathname'' was to be created but the device containing ''pathname'' has no room for the new file.  
+;[ENOMEM]: Insufficient kernel memory was available.  
+;[EMFILE]: The process already has the maximum number of files open.  
+;[ENFILE]: The limit on the total number of files open on the system has been reached.  
  
-__EEXIST__  
-  
-  
-''pathname'' already exists and __O_CREAT__ and  
-__O_EXCL__ were used.  
-  
-  
-__EISDIR__  
-  
-  
-''pathname'' refers to a directory and the access  
-requested involved writing.  
-  
-  
-__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.  
-  
-  
-__ENAMETOOLONG__  
-  
-  
-''pathname'' was too long.  
-  
-  
-__ENOENT__  
-  
-  
-A directory component in ''pathname'' does not exist or  
-is a dangling symbolic link.  
-  
-  
-__ENOTDIR__  
-  
-  
-A component used as a directory in ''pathname'' is not,  
-in fact, a directory, or __O_DIRECTORY__ was specified  
-and ''pathname'' was not a directory.  
-  
-  
-__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.  
-  
-  
-__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.)  
-  
-  
-__EROFS__  
-  
-  
-''pathname'' refers to a file on a read-only filesystem  
-and write access was requested.  
-  
-  
-__ETXTBSY__  
-  
-  
-''pathname'' refers to an executable image which is  
-currently being executed and write access was  
-requested.  
-  
-  
-__EFAULT__  
-  
-  
-''pathname'' points outside your accessible address  
-space.  
-  
-  
-__ELOOP__  
-  
-  
-Too many symbolic links were encountered in resolving  
-''pathname'', or __O_NOFOLLOW__ was specified but  
-''pathname'' was a symbolic link.  
-  
-  
-__ENOSPC__  
-  
-  
-''pathname'' was to be created but the device containing  
-''pathname'' has no room for the new file.  
-  
-  
-__ENOMEM__  
-  
-  
-Insufficient kernel memory was available.  
-  
-  
-__EMFILE__  
-  
-  
-The process already has the maximum number of files  
-open.  
-  
-  
-__ENFILE__  
-  
-  
-The limit on the total number of files open on the system  
-has been reached.  
 !!CONFORMING TO 
+SVr4, SVID, [POSIX], X/OPEN, BSD 4.3  
  
-  
-SVr4, SVID, POSIX, X/OPEN, BSD 4.3 The __O_NOFOLLOW__ and  
-__O_DIRECTORY__ flags are Linux-specific. One may have to  
-define the ___GNU_SOURCE__ macro to get their  
-definitions.  
-!!RESTRICTIONS  
-  
-  
-There are many infelicities in the protocol underlying NFS,  
-affecting amongst others __O_SYNC__ and  
-__O_NDELAY__.  
-  
-  
-POSIX provides for three different variants of synchronised  
-I/O, corresponding to the flags __O_SYNC__,  
-__O_DSYNC__ and __O_RSYNC__. Currently (2.1.130) these  
-are all synonymous under Linux.  
 !!SEE ALSO 
  
-  
- 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)  
-----  
+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.