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

网站建设方面存在的问题公司建设网站需求分析

网站建设方面存在的问题,公司建设网站需求分析,太原网站建设详细策划,文友胜做的网站学习几个常用的Linux系统I/O函数#xff1a;open、close、write、read和lseek。注意#xff0c;系统调用函数必须都考虑返回值。 #xff08;1#xff09;open函数的使用 首先#xff0c;需要包含三个头文件#xff1a;sys/types.h sys/stat.h open、close、write、read和lseek。注意系统调用函数必须都考虑返回值。 1open函数的使用 首先需要包含三个头文件sys/types.h   sys/stat.h   fcntl.h 以如下代码为例 [rootlocalhost src]# ls add.c  div.c  hello  main.c  mul.c  sub.c  zsx  zsx.c [rootlocalhost src]# vim zsx.c #include sys/types.h #include sys/stat.h #include fcntl.h //前三个头文件对应库函数open #include stdlib.h //对应库函数exit #include stdio.h //对应库函数 perror和printf #include unistd.h //对应库函数closeint main( ) {int fd; //记录open函数返回值fd open(zsxhello,O_RDWR); //以读写方式打开一个不存在的文件当前目录printf(fd%d\n,fd);if( fd -1 ) //如果打开失败{perror(open zsxhello); //则输出打开失败的原因详细错误信息exit(1); //并结束当前进程则后面程序不再执行}//如果打开成功继续向后执行 注意exit函数结束当前进程在头文件stdlib.h中声明int ret close( fd ); //打开后关闭该文件printf(ret%d\n,ret);if( ret -1 ) //如果关闭文件失败{perror(close zsxhello); //输出出错的详细信息exit(1);}return 0; }[rootlocalhost src]# gcc -pipe -pedantic -Wall -ggdb3 zsx.c -o zsx [rootlocalhost src]# ldd zsx linux-vdso.so.1   (0x00007fff21f18000) libc.so.6 /lib64/libc.so.6 (0x00007eff28730000) /lib64/ld-linux-x86-64.so.2 (0x00007eff28b10000) [rootlocalhost src]# ./zsx fd-1  //文件打开失败 open zsxhello: No such file or directory   //错误详细信息 //下面说明如何利用open函数创建一个文件 #include sys/types.h #include sys/stat.h #include fcntl.h #include stdio.h #include unistd.hint main( ) {int fd;fd open(hello,O_RDWR); //打开一个已有的文件printf(fd%d\n,fd);if( fd -1 ){perror(open hello);}int fd1 open(zsxhello,O_RDWR | O_CREAT,0777); //创建一个zsxhello文件printf(fd1%d\n,fd1);if( fd1 -1 ){perror(open zsxhello);}int ret close( fd ); //关闭hello文件printf(ret%d\n,ret);if( ret -1 ){perror(close hello);}int ret1 close( fd1 ); //关闭zsxhello文件printf(ret1%d\n,ret1);if( ret1 -1 ){perror(close zsxhello);}return 0; }[rootlocalhost src]# ./zsx fd3   fd14   //可以看到新打开的两个文件描述符为3、4 ret0  ret10   //成功关闭文件 int fd1 open(zsxhello,O_RDWR | O_CREAT,0777);  //创建一个zsxhello文件 O_RDWR | O_CREAT  参数表示创建该文件且以读写的方式打开   0777定义创建文件的权限文件的权限都是8进制数以0开头的数0777等价于777。 [rootlocalhost src]# ls add.c  div.c  hello  main.c  mul.c  sub.c  zsx  zsx.c  zsxhello [rootlocalhost src]# ll zsxhello -r-xr-xr-x. 1 root root 0 Mar 18 18:09 zsxhello [rootlocalhost src]# umask  //掩码操作系统对文件的一种保护机制 0777 注意可看到文件zsxhello的权限并不是0777而是0555。这是因为文件的实际权限与掩码umask有关。因此可以根据掩码值来计算出相应的给定值从而达到自己想要的最终实际值也可以修改掩码 umask 0000  将掩码值修改为 0000 文件权限由open的mode参数和当前进程的umask掩码共同决定 //利用open函数对文件进行截断  O_TRUNC参数 将文件截断就是将文件内容删除一部分留一部分。将文件截断为0就是删除文件全部内容清空。代码如下 #include sys/types.h #include sys/stat.h #include fcntl.h #include stdlib.h #include stdio.h #include unistd.hint main( ) {int fd;fd open(hello,O_RDWR | O_TRUNC); //以读写方式打开hello文件并将其截断为0printf(fd%d\n,fd);if( fd -1 ){perror(open hello);exit(1); //若打开失败退出当前进程此时main函数返回值不再为0}int ret;ret close( fd );printf(ret%d\n,ret);if( ret -1 ){perror(close hello);exit(1); //若关闭失败退出当前进程此时main函数返回值不再为0}return 0; }[rootlocalhost src]# ll hello -rwxrwxrwx. 1 root root 14 Mar 18 16:58 hello [rootlocalhost src]# ./zsx fd3 ret0 [rootlocalhost src]# ll hello -rwxrwxrwx. 1 root root 0 Mar 18 18:38 hello 注意上面代码对于Linux系统I/O函数都有返回值且需要对返回值进行判断并作出相应处理如退出当前进程。 //利用open函数判断文件是否存在  O_CREAT与O_EXCL参数必须同时使用即通过创建文件的方式来判断其是否存在如果存在出错并给出提示。代码如下 #include sys/types.h #include sys/stat.h #include fcntl.h #include stdlib.h #include stdio.h #include unistd.hint main( ) {int fd;fd open(hello,O_RDWR | O_CREAT | O_EXCL,0777); 判断hello文件是否存在 printf(fd%d\n,fd);if( fd -1 ){perror(open hello);exit(1);}int ret;ret close( fd );printf(ret%d\n,ret);if( ret -1 ){perror(close hello);exit(1);}return 0; }[rootlocalhost src]# ./zsx fd-1 open hello: File exists 如果将fd open(hello,O_RDWR | O_CREAT | O_EXCL,0777);    改为  fd open(hello,O_RDWR | O_CREAT,0777);  仍然能正常打开已经存在的文件对于不存在的文件则创建执行结果 [rootlocalhost src]# ./zsx fd3 ret0 2close函数的使用 #include unistd.h  //包含头文件 int close(int fd);    //返回值为0或-10代表关闭文件成功-1代表关闭文件失败。 参数为所要关闭文件的文件描述符。 关闭文件出错则会赋值给errno一个对应的代码值。
http://www.zqtcl.cn/news/640779/

相关文章:

  • 网站开发外包公司坑襄垣城乡建设管理局的网站
  • 网络公司怎么做网站常州新北区网站建设
  • 扬州专业外贸网站建设推广做详情页上什么网站找素材
  • 北京做网站设计招聘深圳市住房和建设局官网平台
  • 冻品网站建设网站头图设计
  • 手机网站分辨率做多大h5微网站建设多少钱
  • 网站制作软件下载公司怎么注册邮箱帐号
  • 做婚纱网站的图片园林设计
  • 濮阳公司建站淮北城市住建网
  • 建设银行网站打不开 显示停止工作专门做地图的网站
  • 有没有人一起做网站app网站建设方案
  • 洛阳网站建设兼职企业网站建设文案
  • 动漫制作贵州seo策略
  • asp网站建设项目实训该怎么跟程序员谈做网站
  • 网站软件资源iis不能新建网站
  • 网站设计的发展趋势西安市建设工程交易网
  • 做外贸收费的服装网站武钢建设公司网站
  • wordpress 全文搜索企业网站优化策略
  • 犀牛云做网站如何网站备案需要什么东西
  • wordpress星座网站建设与优化计入什么科莫
  • 外贸网站优化方案绵阳网站建设怎么做
  • 黑龙江省网站建设电商的运营推广
  • 惠州建站模板wordpress更换主题帖子封面不显示
  • 网站开发为什么不用cgi了营销型网站案例
  • 网站怎么做飘窗电子商城网站建设的实训内容
  • 怎样申请建网站做it公司网站
  • 一个网站费用给人做ppt的网站吗
  • 免费简历在线制作网站杭州市网站建设公司
  • 用家庭宽带做网站 没有8080端口可以吗汕头教育学会网站建设
  • 南通seo公司网站广东涂料网站建设