creatnew
raw OCR
Creates a new file.
Defined in header <dos.h>
Syntax
#include <dos.h>
int creatnew(const char *path, int mode);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ |
Remarks
creatnew is identical to _creat with one exception. If the file exists, creatnew returns an error and leaves the file untouched.
The mode argument to creatnew can be one of the following constants (defined in dos.h):
| FA_RDONLY | Read-only attribute |
| FA_HIDDEN | Hidden file |
FA_SYSTEM System file
Return value
Upon successful completion, creat returns the new file handle, a non-negative integer; otherwise, it returns -1.
In the event of error, the global variable errno is set to one of the following:
| EEXIST | File already exists |
| ENOENT | Path or file name not found |
| EMFILE | Too many open files |
| EACCES | Permission denied |
See also
Example
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <dos.h>
#include <io.h>
int main (void)
{
int handle;
char buf[ll] = "0123456789";
/* attempt to create a file that doesn't already exist */
handle = creatnew ("DUMMY.FIL", 0);
if (handle == -1)
printf("DUMMY.FIL already exists.\n");
else {
printf("DUMMY.FIL successfully created.\n");
write (handle, buf, strlen(buf));
close (handle);
return
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/dos.h/creatnew/
· short form /3.1/creatnew/