open函数原型
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
int creat(const char *pathname, mode_t mode);
测试例子:
70 int iFileID = open("./guimsg.htm",O_WRONLY|O_CREAT );
71 printf("iFileID = %d\n",iFileID);
72 close(iFileID);
73 int iFileID2 = open("./guimsg.htm",O_WRONLY|O_CREAT );
74 printf("iFileID2 = %d\n",iFileID2);
75 close(iFileID2);
76 return 0;
运行发现,多次打开同一个文件,返回的iFileID 是一样的。
打开成功则返回非负的整数
如果打开错误,则返回-1;