Open a file and return a handle for a file object.
RTHANDLE CreateRtFile(
LPSTR lpFileName,
DWORD dwAccessMode,
DWORD dwShareMode,
DWORD dwOpenMode,
DWORD dwAttributesAndFlags);
lpFileName
dwAccessMode
dwShareMode
dwOpenMode
FILE_CREATE_ALWAYS |
Creates a new file, always. If the specified file exists and is writable, the function overwrites the file and the call succeeds. If the path does not exist and is valid, a new file is created and the function succeeds. |
FILE_CREATE_NEW |
Creates a file, only if it does not already exist. If the specified file exists, the function fails and the last error is set to E_FEXIST. If the specified file does not exist and the location path is writable, then a new file is created and function succeeds. |
FILE_OPEN_ALWAYS |
Opens a file, always. If the specified file exists, the function succeeds. If the specified file does not exist, and the location is writable, the file is created and the function succeeds. |
FILE_OPEN_EXISTING |
Opens a file or device, only if it exists. If the specified file does not exist, the function fails and last error is set to E_FNEXIST. |
FILE_TRUNCATE_EXISTING |
Opens a file and truncates it to zero bytes in length, only if it exists. If the specified file does not exist, the function fails and last error is set to E_FNEXIST. The caller must open the file with a writable access mode (WRITE_ONLY or READ_WRITE). |
dwAttributesAndFlags
FILE_ATTR_READONLY |
File is read-only |
FILE_ATTR_HIDDEN |
File is hidden |
FILE_ATTR_SYSTEM |
File is marked as a system file |
FILE_ATTR_ARCHIVE |
File is marked for archiving |
FILE_ATTR_NORMAL |
File is a normal file (no other attribute bits are set) |
FILE_FLAG_ASYNCHRONOUS |
File is opened for asynchronous operations. See the section Synchronous and asynchronous I/O operations for further details. |
If the function succeeds, the return value is a handle for an open file object. If the function fails, the return value is BAD_RTHANDLE. To get extended information call GetLastRtError().
Status value | Meaning |
---|---|
E_FNEXIST | The name given does not belong to an existing file. |
E_PARAM | The file name parameter is NULL, or an invalid value was given for dwAccessMode , dwShareMode or dwOpenMode |
E_SPACE | The volume is full. |
E_PATHNAME_SYNTAX | The pathname was not correctly formed of valid characters. |
E_FEXIST | The file specified already exists and FILE_CREATE_NEW was specified. |
E_FACCESS | The file is not accessible. |
E_IO_HARD | An I/O error occurred during the operation |
When an application is finished using the handle, call DeleteRtFile to close the file object and delete it. This not only frees up the resources associated with the handle but has influence on other things such as the accessibility of the file through sharing, committing the data to the underlying medium and so on. Specifics are described elsewhere in this topic as appropriate.
The only file attributes currently supported on INtime Distributed RTOS are FILE_ATTR_READONLY and FILE_ATTR_HIDDEN.
A directory cannot be created using CreateRtFile. Therefore to open a directory only the OPEN_EXISTING flags value is valid. Use CreateRtDirectory to create a directory.
Versions | Defined in | Include | Link to |
---|---|---|---|
INtime 6.0 | intime/rt/include/rtbase.h | rt.h | rt.lib |