RAD Studio |  |

_rtl_creat, _wrtl_creat

Header File

io.h

Category

Input/output Routines

Prototype

int _rtl_creat(const char *path, int attrib);

int _wrtl_creat(const wchar_t *path, int attrib);

Description

Creates a new file or overwrites an existing one.

Note: The _rtl_creat function replaces _creat,
which is obsolete_rtl_creat opens the file specified by path. The file is always opened in binary mode. Upon successful file creation, 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 its size is reset to 0. (This is essentially the same as deleting the file and creating a new file with the same name.)

The attrib argument is an OR’ed combination of one or more of the following constants (defined in dos.h):

FA_RDONLY | Read-only attribute
FA_HIDDEN | Hidden file
FA_SYSTEM | System file

Return Value

On success, _rtl_creat returns the new file handle (a non-negative integer).

On error, it returns -1 and sets the global variable errno to one of the following values:

EACCESPermission denied

EMFILEToo many open files

ENOENTPath or file name not found

Example

Copy Code

    #include <string.h>
    #include <stdio.h>
    #include <io.h>
    int main() {
      unsigned count;
      int handle;
      char buf[11] = "0123456789";
      /* Create a 10-byte file using _rtl_creat. */
      if ((handle = _rtl_creat("DUMMY2.FIL", 0)) < 0) {
        perror("Unable to _rtl_create DUMMY2.FIL");
        return 1;
      }
      if (_rtl_write(handle, buf, strlen(buf)) < 0) {
        perror("Unable to _rtl_write to DUMMY2.FIL");
        return 1;
      }
      _rtl_close(handle);
      return 0;
    }

Portability

| POSIX | Win32 | ANSI C | ANSI C++
_rtl_crea |  | + |  |
_wrtl_creat |  | NT only |  |

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!