Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ creat(2) — GL1 W2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

close(2)

dup(2)

lseek(2)

open(2)

read(2)

umask(2)

write(2)

CREAT(2)  —  Silicon Graphics

NAME

creat − create a new file or rewrite an existing one

SYNOPSIS

int creat (path, mode)
char ∗path;
int mode;

DESCRIPTION

Creat creates a new ordinary file or prepares to rewrite an existing file named by the path name pointed to by path.

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

All bits set in the process’s file mode creation mask are cleared.  See umask(2).

The “save text image after execution bit” of the mode is cleared.  See chmod(2).

Upon successful completion, a non-negative integer, namely the 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 system calls.  See fcntl(2). No process may have more than 20 files open simultaneously.

The mode given is arbitrary; it need not allow writing.  This feature is used by programs which deal with temporary files of fixed names.  The creation is done with a mode that forbids writing.  Then, if a second instance of the program attempts a creat, an error is returned and the program knows that the name is unusable for the moment.

The system-scheduling algorithm does not make this a true uninterruptible operation, and a race condition may develop if creat is done at precisely the same time by two different processes. 

Creat will fail if one or more of the following are true:

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

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

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

The path name is null.  ­[ENOENT]

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

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

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

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

The named file is an existing directory.  ­[EISDIR]

Twenty (20) file descriptors are currently open.  ­[EMFILE]

Path points outside the process’s allocated address space.  ­[EFAULT]

RETURN VALUE

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

SEE ALSO

close(2), dup(2), lseek(2), open(2), read(2), umask(2), write(2). 

ASSEMBLER

moveq#8,D0
movlpath,A0
movlmode,D1
trap#0

Carry bit set on failure and cleared on success. 

The file descriptor is returned in D0. 

Version 2.1  —  January 02, 1985

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