C函数:_open, _wopen

本文介绍了C语言中的_open和_wopen函数,这两个函数用于打开文件,但已被弃用,推荐使用_sopen_s和_wsopen_s。_open和_wopen根据oflag参数指定的读写模式打开文件,并返回文件描述符。如果使用_O_WTEXT打开文件,会检查文件头以确定文件的字符编码。pmode参数用于指定新建文件的权限设置,只有在指定_O_CREAT时才需要。不正确的oflag或pmode值会导致函数失败并设置errno为EINVAL。
摘要由CSDN通过智能技术生成

Opens a file. These functions are deprecated because more secure versions are available; see _sopen_s, _wsopen_s.

int  _open(  const   char   * filename,   int  oflag [,  int  pmode] );
int  _wopen(  const  wchar_t  * filename,  int  oflag [,   int  pmode] );
Parameters
filename

File name.

oflag

Type of operations allowed.

pmode

Permission mode.

Each of these functions returns a file descriptor for the opened file. A return value of -1 indicates an error, in which case errno is set to one of the following values.

EACCES

Tried to open read-only file for writing, file's sharing mode does not allow specified operations, or given path is directory.

EEXIST

_O_CREAT and _O_EXCL flags specified, but filename already exists.

EINVAL

Invalid oflag or pmode argument.

EMFILE

No more file descriptors available (too many open files).

ENOENT

File or path not found.

For more information about these and other return codes, see _doserrno, errno, _sys_errlist, and _sys_nerr.

The _open function opens the file specified by filename and prepares the file for reading or writing, as specified by oflag. _wopen is a wide-character version of _open; the filename argument to _wopen is a wide-character string. _wopen and _open behave identically otherwise.

Generic-Text Routine Mappings
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值