Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

chmod(2)

close(2)

dup(2)

fcntl(2)

lseek(2)

open(2)

read(2)

umask(2)

write(2)



  creat(2)                            CLIX                            creat(2)



  NAME

    creat - Creates a new file or rewrites an existing one

  LIBRARY

    Standard C Library (libc.a)

  SYNOPSIS

    #include <fcntl.h>

    #include <sys/types.h>

    #include <sys/stat.h>

    int creat(
      char *path ,
      mode_t mode );

  PARAMETERS

    path   Specifies the file to be created.

    mode   Specifies the file permission bits (see the <sys/stat.h> header
           file) of the file to be created except those set in the process'
           file mode creation mask.  (See the umask() function.)  The mode
           parameter does not affect whether the file is opened for reading,
           for writing, or for both.

  DESCRIPTION

    The creat() function creates a new ordinary file or prepares to rewrite an
    existing file named by the pathname pointed to by the path parameter.

    If the file exists, the length is truncated to 0 and the mode and owner
    are unchanged.  Otherwise, the file owner ID is set to the effective user
    ID of the process, the group ID of the process is set to the effective
    group ID of the process, and the low-order 12 bits of the file mode are
    set to the value of mode parameter modified as follows:

    ⊕  All bits set in the process file mode creation mask are cleared.  (See
       the umask() function.)

    ⊕  The ``save text image after execution bit'' of the mode is cleared.
       (See the chmod() function.)

    Upon successful completion, 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 the fcntl()



  2/94 - Intergraph Corporation                                              1






  creat(2)                            CLIX                            creat(2)



    function.)  No process may have more than NOFILES files open
    simultaneously.  A new file may be created with a mode that forbids
    writing.

  EXAMPLES

    To create a new file readable by all users but writable only by the owner
    of the file:

    fd = creat("newfile", 0644);
    if (fd < 0) {
            perror("Could not create newfile");
            return(-1);
    }


  RETURN VALUES

    Upon successful completion, the file descriptor, a non-negative integer,
    is returned.  Otherwise, a value of -1 is returned and the global variable
    errno is set to indicate the error.

  ERRORS

    The creat() function fails if one or more of the following are true:

    [ENOTDIR]
           A component of the path prefix is not a directory.

    [ENOENT]
           A component of the path prefix does not exist.

    [EACCES]
           Search permission is denied on a component of the path prefix.

    [ENOENT]
           The pathname is null.

    [EACCES]
           The file does not exist and the directory in which the file is to
           be created does not permit writing.

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

    [ETXTBSY]
           The file is a pure procedure (shared text) file that is being
           executed.

    [EACCES]
           The file exists and write permission is denied.



  2                                              Intergraph Corporation - 2/94






  creat(2)                            CLIX                            creat(2)



    [EISDIR]
           The named file is an existing directory.

    [EMFILE]
           NOFILES file descriptors are currently open.

    [ENAMETOOLONG]
           The length of the path string exceeds PATH_MAX, or a pathname
           component is longer than NAME_MAX while _POSIX_NO_TRUNC is in
           effect.

    [EFAULT]
           The path parameter points outside the allocated address space of
           the process.

    [ENFILE]
           The system file table is full.

    [EAGAIN]
           The file exists, mandatory file/record locking is set, and there
           are outstanding record locks on the file.  (See the chmod()
           function.)

    [EINTR]
           A signal was caught during the creat() function.

    [ENOLINK]
           The path parameter points to a remote machine and the link to that
           machine is no longer active.

    [EMULTIHOP]
           Components of the path string require hopping to multiple remote
           machines.

    [ENOSPC]
           The file system is out of inodes.

  RELATED INFORMATION

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













  2/94 - Intergraph Corporation                                              3




Typewritten Software • bear@typewritten.org • Edmonds, WA 98026