Open函数——详解

Open函数的函数原型如下:

gcc:  

_CRTIMP int __cdecl _open (const char*, int, ...);

VC6.0:
_CRTIMP int __cdecl _open(const char *, int, ...);

Borland C++Builder:
int   _RTLENTRY _EXPFUNC open(const char _FAR *__path, int __access,... /*unsigned mode*/);

tc3.1:
int _Cdecl _FARFUNC open(const char _FAR *__path, int __access,... /*unsigned mode*/);

tc2.0:
int   _Cdecl open      (const char *path, int access,... /*unsigned mode*/);

 

其中 access的取值有:

 

#define O_RDONLY           1
#define O_WRONLY          2
#define O_RDWR              4

access还可以是以下flag及它们之间的组合而得到的性质:

#define O_CREAT         0x0100     /* create and open file */
#define O_TRUNC         0x0200     /* open with truncation */
#define O_EXCL         0x0400     /* exclusive open */
#define O_APPEND              0x0800     /* to end of file */
#define O_CHANGED              0x1000     /* user may read these bits, but     */
#define O_DEVICE              0x2000     /* only RTL/io functions may touch.     */
#define O_TEXT         0x4000     /* CR-LF translation     */
#define O_BINARY              0x8000     /* no translation     */

 

 

mode 参数仅在access取值为O_CREAT时有效。

 

对于大文件的支持


在WIN32机器:

_lseeki64 _telli64

在Linux上:

#define _FILE_OFFSET_BITS 64

fp = open(filename, O_RDONLY | O_LARGEFILE);

lseek64

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值