C Language and Libraries Help (clang.hlp) (
Table of Contents;
Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
_creat
◄Summary► ◄Example► ◄Up► ◄Contents► ◄Index► ◄Back►
─────Run-Time Library───────────────────────────────────────────────────────
The _creat function either creates a new file or opens and
truncates an existing file. If the file specified by <filename>
does not exist, a new file is created with the given permission
setting and is opened for writing. If the file already exists and
its permission setting allows writing, _creat truncates the file
to length 0, destroying the previous contents, and opens it for
writing.
The permission setting, <pmode>, applies to newly created files
only. The new file receives the specified permission setting after
it is closed for the first time. The integer expression <pmode>
contains one or both of the manifest constants _S_IWRITE and
_S_IREAD, defined in SYS\STAT.H. When both constants are given,
they are joined with the bitwise-OR operator (|). The meaning of
the <pmode> argument is determined by the _S_IWRITE or _S_IREAD
manifest constant.
If write permission is not given, the file is read-only. Note that
all files are always readable; it is not possible to give write-
only permission. Thus, modes _S_IWRITE and _S_IREAD | _S_IWRITE
are equivalent. Under DOS versions 3.0 and later, files opened
using _creat are always opened in compatibility mode (see _sopen).
With DOS32X, the files are always opened with _SH_DENYNO.
The _creat function applies the current file-permission mask to
<pmode> before setting the permissions (see _umask).
Note that the _creat routine is provided primarily for
compatibility with previous libraries. A call to _open with
_O_CREAT and _O_TRUNC in the <oflag> argument is equivalent to
_creat and is preferable for new code.
Return Value
If successful, _creat returns a handle for the created file.
Otherwise, it returns -1 and sets errno to EACCES, EMFILE, or
ENOENT.
-♦-