creat -- Create and Open a File for UNIX Style I/O

SYNOPSIS

 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>

 int creat(const char *name, mode_t mode);
 

DESCRIPTION

creat creates a file and opens it in write-only mode, if the file does not already exist. creat is a special case of the open function. creat(name, mode) is equivalent to open(name, O_WRONLY | O_CREAT | O_TRUNC, mode). The mode function defines file permissions for an HFS file and is otherwise ignored. You do not need to specify mode unless you are opening an HFS file.

RETURN VALUE

creat returns the file number if the file is successfully created and opened or - 1 if it is not.

CAUTION

If you use creat to create a file and then close it without writing any characters, the file may not exist after it is closed. Refer to IBM 370 I/O Concepts for more discussion of this point.

EXAMPLE

  #include <sys/typed.h>
  #include <fcntl.h>

  int cardfile;

     /* Create and open the file.        */
  cardfile = creat("cards",S_IRWXU);
     .
     .     /* file processing statements */
     .
  close(cardfile);    /* Close the file. */
 

RELATED FUNCTIONS

mkdir, open, tmpfile, umask

SEE ALSO


Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.