COHERENT manpages

This page displays the COHERENT manpage for creat() [Create/truncate a file].

List of available manpages
Index


creat() -- System Call (libc)

Create/truncate a file
#include <fcntl.h>
int creat(file, mode)
char *file; int mode;

creat() creates a new file or truncates an existing file. It returns a file
descriptor  that identifies  file  for subsequent  system  calls.  If  file
already exists, its contents are erased.  In this case, creat() ignores the
specified mode; the  mode of the  file remains unchanged.  If  file did not
exist previously,  creat() uses the mode argument to  determine the mode of
the  new file.  For a  full definition  of file modes,  see chmod()  or the
header file stat.h. creat() masks the mode argument with the current umask,
so it is common practice to create files with the maximal mode desirable.

Example

For an example of how to use this routine, see the entry for open().

See Also

chmod(),
fcntl.h,
fopen(),
libc,
open(),
stat.h,
stdio.h
ANSI Standard, §4.9.3
POSIX Standard, §5.3.2

Diagnostics

If the  call is successful, creat() returns a  file descriptor.  It returns
-1  if it  could not  create  the file,  typically because  of insufficient
system resources or protection violations.