文件常量File Constants

语法Syntax


#include <fcntl.h>  

备注Remarks

由这些常量中的一个或多个常量构成的整数表达式确定允许进行的读取或写入操作的类型。The integer expression formed from one or more of these constants determines the type of reading or writing operations permitted. 它是通过将一个或多个常量与平移模式常量组合来构成的。It is formed by combining one or more constants with a translation-mode constant.

文件常量如下所示:The file constants are as follows:

_O_APPEND
在每次执行写入操作前,将文件指针重新定位到文件尾。Repositions the file pointer to the end of the file before every write operation.

_O_CREAT
创建一个文件并打开该文件以进行写入;如果有由 filename 指定的文件存在,则此操作不起作用。Creates and opens a new file for writing; this has no effect if the file specified by filename exists.

_O_EXCL
如果由 filename 指定的文件存在,则将返回一个错误值。Returns an error value if the file specified by filename exists. 仅在与 _O_CREAT 一起使用时适用。Only applies when used with _O_CREAT.

_O_RDONLY
打开文件以仅供读取;如果提供此标志,则无法提供 _O_RDWR_O_WRONLYOpens file for reading only; if this flag is given, neither _O_RDWR nor _O_WRONLY can be given.

_O_RDWR
打开文件以供读取和写入;如果提供此标志,则无法提供 _O_RDONLY_O_WRONLYOpens file for both reading and writing; if this flag is given, neither _O_RDONLY nor _O_WRONLY can be given.

_O_TRUNC
打开现有文件并将其截断为零长度;此文件必须具有写入权限。Opens and truncates an existing file to zero length; the file must have write permission. 销毁此文件的内容。The contents of the file are destroyed. 如果提供此标志,则无法指定 _O_RDONLYIf this flag is given, you cannot specify _O_RDONLY.

_O_WRONLY
打开文件以仅供写入;如果提供此标志,则无法提供 _O_RDONLY_O_RDWROpens file for writing only; if this flag is given, neither _O_RDONLY nor _O_RDWR can be given.

另请参阅See Also

_open、_wopen _open, _wopen
_sopen、_wsopen _sopen, _wsopen
全局常量Global Constants