Header File
io.h
Category
Input/output Routines
Prototype
int _rtl_open(const char *filename, int oflags);
int _wrtl_open(const wchar_t *path, int oflags);
Description
Opens a file for reading or writing.
oflags uses the flags from the following two lists. Only one flag from List 1 can be used (and one must be used) and the flags in List 2 can be used in any logical combination.
O_RDONLY |
Open for reading. |
O_WRONLY |
Open for writing. |
O_RDWR |
Open for reading and writing. |
The following additional values can be included in oflags (using an OR operation):
O_NOINHERIT |
The file is not passed to child programs. |
SH_COMPAT |
Allow other opens with SH_COMPAT. All other openings of a file with the SH_COMPAT flag must be opened using SH_COMPAT flag. You can request a file open that uses SH_COMPAT logically OR’ed with some other flag (for example, SH_COMPAT | SH_DENWR is allowed). The call will fail if the file has already been opened in any other shared mode. |
SH_DENYRW |
Only the current handle can have access to the file. |
SH_DENWR |
Allow only reads from any other open to the file. |
SH_DENYRD |
Allow only writes from any other open to the file. |
SH_DENYNO |
Allow other shared opens to the file, but not other SH_COMPAT opens. |
The maximum number of simultaneously open files is defined by HANDLE_MAX.
Return Value
On success:_rtl_open returns a non-negative integer (the file handle). The file pointer, which marks the current position in the file, is set to the beginning of the file.
On error, it returns -1 and sets the global variable errno to one of the following values:
EACCES |
Permission denied |
EINVACC |
Invalid access code |
EMFILE |
Too many open files |
ENOENT |
Path or file not found |
Example
#include <string.h> #include <stdio.h> #include <fcntl.h> #include <io.h> int main(void) { int handle; char msg[] = "Hello world"; if ((handle = _rtl_open("TEST.$$$", O_RDWR)) == -1) { perror("Error:"); return 1; } _rtl_write(handle, msg, strlen(msg)); _rtl_close(handle); return 0; }
Portability
|
POSIX |
Win32 |
ANSI C |
ANSI C++ |
_rtl_open |
|
+ |
|
|
_wrtl_open |
|
NT only |
|
|
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|