Opens a file for reading, writing, or both. Also used to create a file.
#include <prio.h> PRFileDesc* PR_Open( const char *name, PRIntn flags, PRIntn mode);
The function has the following parameters:
- The pathname of the file to be opened.
- The file status flags define how the file is accessed. It is a bitwise
ORof the following bit flags. In most cases, only one of the first three flags may be used. If the
flagsparameter does not include any of the first three flags (
PR_RDWR), the open file can't be read or written, which is not useful.
Name Value Description
0x01 Open for reading only.
0x02 Open for writing only.
0x04 Open for reading and writing.
If the file does not exist, the file is created. If the file exists, this flag has no effect.
The file pointer is set to the end of the file prior to each write.
If the file exists, its length is truncated to 0.
If set, each write will wait for both the file data and file status to be physically updated.
PR_CREATE_FILE, if the file does not exist, the file is created. If the file already exists, no action and NULL is returned.
PR_CREATE_FILEflag is set and the file is created, these flags define the access permission bits of the newly created file. This feature is currently only applicable on Unix platforms. It is ignored by any other platform but it may apply to other platforms in the future. Possible values of the
modeparameter are listed in the table below.
Name Value Description
0700 read, write, execute/search by owner.
0400 read permission, owner.
0200 write permission, owner.
0100 execute/search permission, owner.
0070 read, write, execute/search by group
0040 read permission, group
0020 write permission, group
0010 execute/search permission, group
0007 read, write, execute/search by others
0004 read permission, others
0002 write permission, others
0001 execute/search permission, others
The function returns one of the following values:
- If the file is successfully opened, a pointer to a dynamically allocated
PRFileDescfor the newly opened file. The
PRFileDescshould be freed by calling
- If the file was not opened successfully, a
PR_Open creates a file descriptor (
PRFileDesc) for the file with the pathname
name and sets the file status flags of the file descriptor according to the value of
flags. If a new file is created as a result of the
PR_Open call, its file mode bits are set according to the