creat
Creates and opens a file or stream
#include <fcntl.h>
int creat (
const char *filename,
int permission);
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:
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):
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.
#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);
}