creat(), creat64()

create a new file 

Function


SYNOPSIS

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

int creat(const char *pathname, mode_t mode);

int creat64(const char *pathname, mode_t mode);


DESCRIPTION

The creat() function either creates a new file or prepares to rewrite an existing file named by the path name pointed to by pathname. The function call:

creat(pathname, mode);

is equivalent to:

open(pathname, O_WRONLY | O_CREAT | O_TRUNC, mode);

If the file exists, the length is truncated to 0 and the mode and owner are unchanged.

The creat64() function is a part of the large-file extensions, and is equivalent to calling creat() with the O_LARGEFILE flag.

If the file does not exist, the file's owner ID is set to the effective user ID of the process. The group ID of the file is set to the effective group ID of the process. The access permission bits of the file mode are set to the value of mode, with all bits set in the process's file mode creation mask cleared (see umask()).

On success, a write-only file descriptor is returned and the file is open for writing, even if the mode does not permit writing. The file pointer is set to the beginning of the file. The file descriptor is set to remain open across exec() functions (see fcntl()). A new file may be created with a mode that forbids writing.


PARAMETERS

pathname 

Points to the path name of the file to create.

mode 

Specifies the permission modes associated with the created file.


RETURN VALUES

If successful, creat() and creat64() return a nonnegative integer, which is the lowest numbered unused valid file descriptor. On failure, they return -1, do not create or modify any files, and set errno to one of the following values:

EACCES 

Search permission is denied on a component of the pathname prefix. Or the file does not exist and the directory in which the file is to be created does not permit writing. Or the file exists and write permission is denied.

EAGAIN 

The file exists and write permission is denied.

EFAULT 

pathname points outside the allocated address space of the process.

EINTR 

A signal interrupted the call.

EISDIR 

The named file is an existing directory.

EMFILE 

The process has too many open files.

ENAMETOOLONG 

The length of the path name parameter exceeds PATH_MAX or the length of a path name component exceeds NAME_MAX.

ENFILE 

The system file table is full.

ENOENT 

A component of the pathname prefix does not exist, or pathname is null.

ENOTDIR 

A component of the path name prefix is not a directory.

EROFS 

The named file resides or would reside on a read-only file system.


CONFORMANCE

POSIX.1 (1996), with exceptions.

creat64(): Large File Specification, revision 1.5.


MULTITHREAD SAFETY LEVEL

Async-signal-safe.


PORTING ISSUES

Refer to Security and File Management in the Windows Concepts chapter of the PTC MKS Toolkit UNIX to Windows Porting Guide for a detailed discussion of file security and file handling issues.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
chmod(), close(), dup(), fcntl(), lseek(), open(), read(), stat(), umask(), write()

Miscellaneous:
lf64, struct stat


PTC MKS Toolkit 10.4 Documentation Build 39.