PR_Open 编辑

Opens a file for reading, writing, or both. Also used to create a file.

Syntax

#include <prio.h>

/wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRFileDesc* PR_Open(
  const char *name,
  /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRIntn flags,
  /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRIntn mode);

Parameters

The function has the following parameters:

name
The pathname of the file to be opened.
flags
The file status flags define how the file is accessed. It is a bitwise OR of the following bit flags. In most cases, only one of the first three flags may be used. If the flags parameter does not include any of the first three flags (PR_RDONLY, PR_WRONLY, or PR_RDWR), the open file can't be read or written, which is not useful.

NOTE: The constants PR_RDWR and friends are not in any interface (bug 433295). Thus they cannot be used in JavaScript, you have to use the octal constants (see File I/O Snippets).

NameValueDescription
PR_RDONLY0x01Open for reading only.
PR_WRONLY0x02Open for writing only.
PR_RDWR0x04Open for reading and writing.
PR_CREATE_FILE0x08

If the file does not exist, the file is created. If the file exists, this flag has no effect.

PR_APPEND0x10

The file pointer is set to the end of the file prior to each write.

PR_TRUNCATE0x20

If the file exists, its length is truncated to 0.

PR_SYNC0x40

If set, each write will wait for both the file data and file status to be physically updated.

PR_EXCL0x80

With PR_CREATE_FILE, if the file does not exist, the file is created. If the file already exists, no action and NULL is returned.

 

mode
When PR_CREATE_FILE flag 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 mode parameter are listed in the table below.
NameValueDescription
PR_IRWXU0700read, write, execute/search by owner.
PR_IRUSR0400read permission, owner.
PR_IWUSR0200write permission, owner.
PR_IXUSR0100execute/search permission, owner.
PR_IRWXG0070read, write, execute/search by group
PR_IRGRP0040read permission, group
PR_IWGRP0020write permission, group
PR_IXGRP0010execute/search permission, group
PR_IRWXO0007read, write, execute/search by others
PR_IROTH0004read permission, others
PR_IWOTH0002write permission, others
PR_IXOTH0001execute/search permission, others

Returns

The function returns one of the following values:

Description

PR_Open creates a file descriptor (/wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/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 mode parameter.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:38 次

字数:6540

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文