creat

Creates and opens a file or stream

Local Servers:blocking
Remote Servers:blocking
Classification:POSIX
Platform:NLM
Service:Operating System I/O

Syntax

  #include <fcntl.h>  
   
  int creat  (  
     const char  *filename,   
     int          permission);
  

Parameters

filename
(IN) Points to the name of the file to be created (considered within the context of the currently set name space).
permission
(IN) Specifies the access permissions for the file.

Return Values

When an error occurs while creating the file, a value of -1 is returned. Otherwise, an integer (not equal to -1), known as the file handle, is returned to be used with the other functions that operate on the file.

When an error occurs, errno can be set to:

Decimal

Constant

Description

1

ENONENT

No such file.

6

EACCES

Permission denied.

9

EINVAL

Invalid argument.

When an error occurs, NetWareErrno is set to:

Decimal

Hex

Constant

Description

152

(0x98)

ERR_INVALID_VOLUME

 

156

(0x9C)

ERR_INVALID_PATH

 

191

(0xBF)

ERR_INVALID_NAME_SPACE

On remote servers when using a non-DOS name space.

Remarks

This function also works on the DOS partition.

This function allows for as many open files as there is available memory. The filename parameter supplies the name of the file to be created. If the file exists (the current connection must have Write rights), it is truncated to contain no data and the preceding permission setting is unchanged.

If the file does not exist, it is created with access permission given by the permission parameter.

The access permission for the file is specified as a combination of bits (defined in the SYS\STAT.H header file):

S_IWRITE

The file is writable.

S_IREAD

The file is readable.

The permission parameter can be specified as S_IWRITE, S_IREAD or S_IWRITE|S_IREAD. Specifying 0 also makes a file both writable and readable.

The current connection must have Create rights to create a new file or have Read/Write rights to write to a file that already exists.

See Also

dup, dup2, open, sopen

Example

  #include   <stddef.h>  
  #include   <fcntl.h>  
  #include   <errno.h>  
  #include   <string.h>  
   
  main()  
  {  
     int   fh;  
     if((fh = creat("name",0)) == -1)  
        printf ("creat() error\n");  
     else  
        close (fh); 
  }