CREAT(2)

NAME
creat, bcreat - create a new file

SYNOPSIS
int creat(name, mode)
char *name;

int bcreat(name, mode, name2)
char *name, name2[14];

DESCRIPTION
Creat creates a new file or prepares to rewrite an existing file called name, given as the address of a null-terminated string. If the file is new, its inode is initialized as follows. The owner of the file is the effective userid of the creating process. The group of the file is the group of the containing directory. The mode of the file is mode, as modified by the process's mode mask; see umask(2). Setgid is turned off if the effective groupid of the process differs from the groupid of the file. See stat(2) for the encoding of modes.

If the file did exist, its mode and owner remain unchanged. The file is truncated to 0 length unless it is append-only; see stat(2).

The file is opened for writing, and its file descriptor is returned.

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 file is created 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.

Bcreat performs the function of creat, and then, if successful, copies the last component of the actual pathname of the created file as a NUL-padded string into name2. It is intended for use with blind directories, where new entries are created under random names; see mkdir(2).

It is not possible to create or open for writing a file with set-userid or set-groupid permission; see stat(2).

SEE ALSO
chmod(2), close(2), umask(2), write(2)

DIAGNOSTICS
EACCES, EBADF, EBUSY, EFAULT, EIO, EISDIR, ELAB, ELOOP, EMFILE, ENFILE, ENOENT, ENOTDIR, EROFS, ETXTBSY