Borland C++ reference

_dos_creatnew

raw OCR

Creates a new file.

Defined in header <dos.h>

Syntax

#include <dos.h>
unsigned  _dos_creatnew(const   char *path, int attrib,int*handlep);

Portability

DOSUNIXWindowsANSI CC++ 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_NORMALNormal file
A_RDONLYRead-only file
A_HIDDENHidden file
A SYSTEMSystem 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:

EEXISTFile already exists
ENOENTPath or file name not found
EMFILEToo many open files
EACCESPermission 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`