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