_dos_creatnew
Creates a new file.
Defined in header <dos.h>
Syntax
#include <dos.h>
unsigned _dos_creatnew(const char *path, int attrib,int*handlep);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ |
Remarks
_dos_creatnew uses DOS function 0x5B to create and open the new file path. The file is given the access permission attrib, a DOS attribute word. The file is always opened in binary mode. Upon successful file creation, the file handle is stored in the location pointed to by handlep, and the file pointer is set to the beginning of the file. The file is opened for both reading and writing.
If the file already exists, _dos_creatnew returns an error and leaves the file untouched.
The attrib argument to _dos_creatnew is an OR combination of one or more of the following constants (defined in dos.h):
| A_NORMAL | Normal file |
| A_RDONLY | Read-only file |
| A_HIDDEN | Hidden file |
| A SYSTEM | System file |
Return value
Upon successful completion, _dos_creatnew returns 0. Otherwise, it returns the DOS error code, and 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 <dos.h>
#include <string.h>
#include <stdio.h>
int main(void)
{
unsigned count;
int handle;
char buf[ll] = "0123456789";
/* create a file containing 10 bytes */
if {_dos_creatnew{"DUMMY.FIL", _A_NORMAL, &handle) != 0)
perror( "Unable to create DUMMY.FIL");
return 1;
}
if (_dos_write(handle, buf, strlen(buf), &count) != 0) {
perror( "Unable to write to DUMMY.FIL");
return 1;
/* close the file */
_dos_close (handle);
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Extraction notes
- heading `dos creatnew` read as `_dos_creatnew`
Stable link: /3.1/dos.h/_dos_creatnew/
· short form /3.1/_dos_creatnew/