当前位置: 首页 > news >正文

章贡区网站建设一个新品牌怎样营销推广

章贡区网站建设,一个新品牌怎样营销推广,有口碑的南昌网站建设,o2o与网站建设论文作用&#xff1a;使用open()打开或创建文件&#xff0c;为后面对文件进行操作做准备。 ubuntu所在目录&#xff1a;usr/include/fcntl.h 在<fcntl.h>里声明 extern int open (const char *__file, int __oflag, …); 参数解析&#xff1a; 一、第一个参数filename:指定路…

作用:使用open()打开或创建文件,为后面对文件进行操作做准备。
ubuntu所在目录:usr/include/fcntl.h
在<fcntl.h>里声明
extern int open (const char *__file, int __oflag, …);
参数解析:
一、第一个参数filename:指定路径的文件名字
二、第二个参数flags:对打开或创建的文件的操作权限
1.必选项
1).O_RDONLY //只读
2).O_WRONLY //只写
3).O_RDWR //读写
2.可选项
1).O_CREAT //如果指定文件不存在,创建文件
注:Linux用open创建的文件,其实际的操作权限为代码里设置的权限和本地掩码按位与(&)
2).O_EXCL //和O_CREAT一起使用,可以判断文件是否存在
3).O_TRUNC //截断文件,当文件存在且可写打开时,使文件长度为0,并清空文件的内容
三、第三个参数,一般在创建文件的时候给创建的文件操作权限,与O_CREAT一起使用

测试代码

#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>    //open()
#include<unistd.h>  //close()
#include<stdlib.h>  //exit()
#include<stdio.h>   //perror()int main(void)
{int fd1;       //文件描述符:一个整形数组(0~1023),0~2为系统默认打开的文件int res;#ifdef HELLO//打开一个不存在的文件fd1 = open("hello",O_RDWR); //返回对应的文件描述符,第一个参数是文件路径及名称,第二个参数为操作方式,O_RDWR为读操作if(fd1 == -1)    //-1 表示失败{perror("open file hello");  //perror打印错误信息,系统的errno代表的文字信息exit(1);}else{printf("open hello fd1 = %d\n",fd1);//关闭文件res = close(fd1);            //传递要关闭的文件的文件描述符printf("close fd1 res = %d\n",res); //返回0关闭成功,-1失败if(res == -1){perror("close fd1");exit(1);}}
#endif//打开一个已经存在的文件int fd2 = open("hello_open.c",O_RDWR);if(fd2 == -1){perror("open file hello_open.c");exit(1);}else{printf("hello_open.c fd2 = %d\n",fd2);res = close(fd2);            printf("close fd2 res = %d\n",res); if(res == -1){perror("close fd2");exit(1);}}//创建新文件:O_CREATint fd3 = open("CreateFile", O_CREAT | O_RDWR, 0777); if(fd3 == -1){perror("create file");exit(1);}else {printf("CreatFile fd3 = %d\n",fd3);res = close(fd3);            printf("close fd3 res = %d\n",res); if(res == -1){perror("close fd3");exit(1);}}//#define EXCL
#ifdef EXCL//判断文件是否存在:O_EXCLint fd4 = open("CreateFile", O_CREAT | O_EXCL | O_RDWR, 0777);if(fd4 == -1){ //文件已经存在,创建失败perror("create and testEXCL file");exit(1);}else {printf("EXCLtest fd4 = %d\n",fd4);res = close(fd4);            printf("close fd4 res = %d\n",res); if(res == -1){perror("close fd4");exit(1);}}
#endif#define TRUNC
#ifdef TRUNC //将文件截断为0int fd5 = open("hello_open.c", O_RDWR | O_TRUNC);if(fd5 == -1){perror("trunc file");exit(1);}else {printf("trunc fd5 = %d\n",fd5);res = close(fd5);            printf("close fd5 res = %d\n",res); if(res == -1){perror("close fd5");exit(1);}}
#endif return 0;
}

注:O_TRUNC 使用前后对比

zhangqu@zhangqu:~/system_function_test/IO/open$ ls -l hello_open.c 
-rw-rw-r-- 1 zhangqu zhangqu 97 5月   6 22:02 hello_open.c
zhangqu@zhangqu:~/system_function_test/IO/open$ gcc open_test.c -o myopen
zhangqu@zhangqu:~/system_function_test/IO/open$ ./myopen 
hello_open.c fd2 = 3
close fd2 res = 0
CreatFile fd3 = 3
close fd3 res = 0
trunc fd5 = 3
close fd5 res = 0
zhangqu@zhangqu:~/system_function_test/IO/open$ ls -l hello_open.c 
-rw-rw-r-- 1 zhangqu zhangqu 0 5月   6 22:05 hello_open.c
zhangqu@zhangqu:~/system_function_test/IO/open$ 
http://www.lbrq.cn/news/2757205.html

相关文章:

  • 网站备案名称几个字常用seo站长工具
  • 做商务网站服务google推广及广告优缺点
  • 网站建设公司渠道自己怎么做百度推广
  • 济南百度推广电话成都seo培训
  • 网站从设计到制作做一个公司网站大概要多少钱
  • 网站开发进度设计站长之家产品介绍
  • 做h5网站pc加手机版要多少钱学生网页制作成品
  • kotlin做网站seo免费培训视频
  • 记事本怎么做网站图片链接怎么进行网站关键词优化
  • 大庆公司做网站怎样制作网页设计
  • 自学编程网站广州seo优化公司
  • 上海做网站多少钱seo引擎优化是什么
  • 小榄公司网站建设著名的网络营销案例
  • 企业查查app下载seo搜索引擎优化课程总结
  • 哪个网站做废旧好手机百度收录提交入口
  • 武汉网站建设团队seo网站推广软件
  • 晋江网站开发谷歌推广新手教程
  • java程序员转网站开发怎么做app推广
  • 论坛网站地图怎么做成人馆店精准引流怎么推广
  • 做暖暖视频网站有哪些百度推广关键词技巧定价
  • 医疗协助平台网站建设方案我想接app纯注册推广单
  • 连云港专业做网站江北seo页面优化公司
  • 做宣传单页的网站汽车营销活动策划方案
  • 做网站租服务器一年多少钱自己的网站怎么做seo
  • 做网站之前要安装什么搜索引擎网站优化和推广方案
  • 设计师网站pintset关键词林俊杰百度云
  • 西安网站建设公司哈尔滨百度推广联系人
  • 做网站 收费广告推广方案怎么写
  • app软件下载安装官方免费下载文章优化软件
  • wordpress根据用户名生成头像百度关键词优化多久上首页
  • 【Jenkins】03 - 自动构建和docker构建
  • LLM - MCP传输协议解读:从SSE的单向奔赴到Streamable HTTP的双向融合
  • 基于Spring Boot+Vue的社区便民服务平台 智慧社区平台 志愿者服务管理
  • 新手向:Java方向讲解
  • Java面试宝典:Redis高级特性和应用(发布 订阅、Stream)
  • TOGAF八步一法笔记2