Borland C++ reference

creatnew

raw OCR

Creates a new file.

Defined in header <dos.h>

Syntax

#include <dos.h>
int creatnew(const char *path, int mode);

Portability

DOSUNIXWindowsANSI CC++ 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_RDONLYRead-only attribute
FA_HIDDENHidden 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:

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