HP 3000 Manuals

creat [ MPE/iX Developer's Kit Reference Manual Volume I ] MPE/iX 5.0 Documentation


MPE/iX Developer's Kit Reference Manual Volume I

creat 

Creates a new file or rewrites an existing file.

Syntax 

     #include <sys/types.h>
     #include <sys/stat.h>
     #include <fcntl.h>
     int creat (const char *pathname, mode_t mode);

Parameters 

pathname   A pointer to a string containing the pathname of a file to be
           created or rewritten.  The pathname must be terminated by a
           null character.

mode       File access permission bits.  If the file already exists, mode 
           is ignored.  Access permission bits are set by ORing any
           combination of the following macros:

           S_IRWXU       Set file owner class read, write, and execute
                         (if a file) or search (if a directory)
                         permission bits.

           S_IRUSR       Set file owner class read permission bit.

           S_IWUSR       Set file owner class write permission bit.

           S_IXUSR       Set file owner class execute (if a file) or
                         search (if a directory) permission bit.

           S_IRWXG       Set file group class read, write, and execute
                         (if a file) or search (if a directory)
                         permission bits.

           S_IRGRP       Set file group class read permission bit.

           S_IWGRP       Set file group class write permission bit.

           S_IXGRP       Set file group class execute (if a file) or
                         search (if a directory) permission bit.

           S_IRWXO       Set file other class read, write, and execute
                         (if a file) or search (if a directory)
                         permission bits.

           S_IROTH       Set file other class read permission bit.

           S_IWOTH       Set file other class write permission bit.

           S_IXOTH       Set file other class execute (if a file) or
                         search (if a directory) permission bit.

Return Values 

>=0        Success.  A nonnegative integer is returned representing the
           lowest numbered file descriptor not open by the calling
           process.

-1         An error occurred.  The file is not opened, and errno is set
           to indicate the error condition.

Description 

The creat() function opens for write-only access a file whose pathname is
specified in the string pointed to by pathname.

The creat() function establishes the connection between a file and a file
descriptor.  It creates an open file description that refers to a file,
and a file descriptor that refers to that open file description.  The
file descriptor is used by other I/O functions to refer to the file.

The creat() function returns a file descriptor for the specified file
which is the lowest file descriptor not currently open for the calling
process.  The open file description is new; therefore, the file
descriptor does not share it with any other process in the system.

If the file does not already exist, the file is created and the following
occurs:

   *   The file offset is set to the beginning of the file.
   *   The file is opened for O_WRONLY access.
   *   The file's UID is set to the effective UID of the calling process.
   *   The file's GID is set to the GID of the directory in which the
       file is being created.
   *   The file permission bits of the file are set to mode and modified
       by the file mode creation mask of the calling process.
   *   The following file time fields are marked for update:
          *   the file's st_atime, st_ctime and st_mtime time fields
          *   the parent directory's st_ctime and st_mtime time fields

If the file already exists, the following occurs:

   *   The file is truncated to zero length, and the file offset is set
       to the beginning of the file.
   *   The file's UID, GID, and mode remain unchanged.
   *   The st_ctime and st_mtime time fields of the file are marked for
       update.

The function call

     creat (path, mode);

is equivalent to

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

Implementation Considerations 

Refer to the EACCES, EEXCL, EFAULT, EIMPL, EINVAL, EMFILE, and ESYSERR
error descriptions in the error section of the open() function
description.

Pipes (or FIFOs), device special files, and read-only file systems are
not supported through POSIX/iX interfaces and cannot be opened by
creat().  Device files are inherited from the parent process, which has
them opened as STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO.

The GID of a newly created file is set to the GID of the directory in
which the file is created.

MPE/iX file equations are ignored by creat().

The calling process must have the correct access permissions as defined
by either an attached ACD or by the MPE/iX file security matrix.  The
calling process must have either ACD write access and append access or
MPE/iX write access and append access.

Signals generated for the calling process during execution of open() are
deferred from delivery until completion of this function.

Errors 

Refer to the error section of the open() function description for errors
returned by creat().  Possible errors returned by creat() are the same as
those returned by open() when oflag is set to (O_WRONLY | O_CREAT |
O_TRUNC).

See Also. 

open(), close(), dup(), execl(), execv(), <fcntl.h>, lseek(), read(),
<signal.h>, fstat(), stat(), <stat.h>, write(), umask(), POSIX.1 (Section
5.3.2)



MPE/iX 5.0 Documentation