您的位置:首页 > 产品设计 > UI/UE

【Uinx高级环境变成】1.open函数

2014-02-20 20:51 85 查看

1.open函数

说明:
调用open函数打开或者创建一个文件。函数定义如下:
#include <fcntl.h>
int open(const char *pathname, int flag);
int open(const char *pathname, int flag, mode_t mode);//只有新创建文件时才会使用该函数
//返回值,如果成功返回文件描述符,如果出错返回-1
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
int main (){
int fd ;
if( (fd = open ("./a.txt",O_RDWR|O_CREAT|O_EXCL,S_IRUSR)) < 0)
perror ("fail open");
else printf ("success");
return 0 ;
}


执行后创建文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: