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

自助游网站开发分析报告搜狗seo培训

自助游网站开发分析报告,搜狗seo培训,网站在线客服tq,学历网站怎么做系统调用 由操作系统实现并提供给外部应用程序的编程接口(API)。是应用程序同系统之间数据交换的桥梁。 文件IO 函数 open/close函数 头文件 #include<fcntl.h> #include<unistd.h>int open(const char*pathname , int flags) int open(const char*pathname , …

系统调用

由操作系统实现并提供给外部应用程序的编程接口(API)。是应用程序同系统之间数据交换的桥梁。

文件IO

函数

open/close函数

头文件
#include<fcntl.h>
#include<unistd.h>int open(const char*pathname , int flags)
int open(const char*pathname , int flags , mode_t mode)#mode 执行权限 777 0等
int create(const char *pathname , mode_t mode)flags: 文件打开方式
O_RDONLY | O_WRONLY | O_RDWR    O_CREAT | O_APPEND | O_TRUNC | O_EXCL |O_NONBLOCK

创建文件的权限还受umask影响

错误处理函数:  与error相关

printf("xxx error:%d\n",error);
char* strerror(int errnum);
print("xxx error:%s\n",strerror(errno))

read函数

ssize_t read(int fd , void *buf , size_t count);fd: 文件描述符
buf: 存数据的缓冲区
count: 缓冲区的大小
返回值:成功:读到的字节数   返回0的时候到达文件结尾
失败 -1 设置errno
-1 , 并且errno=EAGIN or EWOULDBLOCK 说明不是读写失败而是read在以非阻塞方式读一个设备或网络文件,并且文件无数据。

write函数(同上)

ssize_t write(int fd , const void *buf , size_t count);
buf: 待写出数据的缓冲区
count: 数据的大小返回值: 成功 写入的字节数
失败 -1 设置errno

写一个自己的cp函数 , 写系统函数调用的时候都要加上调试信息 也就是 判断是否会出错。


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<pthread.h>
#include<fcntl.h>int main(int argc , char *argv[])
{char buf[1024];int fd1 = open(argv[1] , O_RDONLY); // readif(fd1 == -1){perror("open argv1 error");exit(1);}int fd2 = open(argv[2],O_RDWR | O_CREAT | O_TRUNC , 0664);if(fd2 == -1){perror("open argv2 error");exit(1);}int n = 0 ;while((n = read(fd1 , buf , 1024))!= 0 ){if(n < 0 ){perror("read error");break;}write(fd2 , buf , n);}close(fd1);close(fd2);return 0 ;
}

 优先使用库函数。

 文件描述符

PCB:进程控制块 ,本质是结构体

成员: 文件描述表

文件描述符:0、1、2、、1023  表中可用最小的

0--STDIN_FILENO

1--STDOUT_FILENO

2--STDER_FILENO

阻塞和非阻塞 

产生阻塞的场景:读设备文件 读网络文件(读常规文件无阻塞概念)

是设备网络文件的属性 

/dev/tty  --终端文件。  

fcntl函数

改变一个已经打开文件的访问控制属性 

int flgs = fcntl(fd , F_GETFL);
flgs |= O_NONBLOCK
fcntl(fd , F_SETFL , flgs); //设置为非阻塞状态
获取文件状态:F_GETFL
设置文件状态:F_SETFL

lseek函数

off_t lseek(int fd , off_t offset , int whence);fd: 文件描述符
offset: 偏移量
whence: 起始偏移位置: SEEK_SET/CUR/END
返回值:  成功:较起始位置偏移量-1

文件的读和写使用同一偏移位置

应用场景:文件的读写使用同一偏移位置

                  使用lseek获取、拓展文件大小:要想使文件真正拓展,必须要引起文件IO操作。

还可以使用truncate函数直接拓展 int ret = truncate("文件名", len);

ret = 0 拓展成功。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<pthread.h>
#include<fcntl.h>int main(int argc , char *argv[])
{int fd = open(argv[1] , O_RDWR);if(fd == -1){perror("open error");exit(1);}int len = lseek(fd , 0 , SEEK_END);// int len = lseek(fd , 111 , SEEK_END); // 拓展文件大小printf("file size : %d\n" , len);// write(fd , "a" , 1);close(fd);return 0 ;
}

理解就是将文件指针放到文件末尾,然后设置偏移量为0,返回的就是文件起始位置到文件指针的距离。

传入参数:

        1:指针作为函数参数
        2:通常带有const关键字修饰
        3:指针指向有效区域,在函数内部做读操作
传出参数:

        1:指针作为函数参数
        2:在函数调用之前,指针指向的空间可以无意义,但必须有效
        3:在函数内部,做写操作
        4:函数调用结束后,充当函数返回值
传入传出参数:

        1:指针作为函数参数
        2:在函数调用之前,指针指向的空间要有实际意义
        3:在函数内部,先做读操作,后做写操作
        4:函数调用结束后,充当函数返回值

文件系统

inode

其本质为结构体,存储文件的属性信息。

dentry

目录项,其本质也是结构体 包含文件名和inode

 stat函数/lstat函数

int stat(const char *path , struct stat *buf)
成功返回0
失败返回-1  设置errno

获取文件属性,从inode中获取 , 文件属性将通过传出参数struct stat *buf返回给调用者。

获取文件大小 要包含头文件#include<sys/stat.h>  

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<pthread.h>
#include<sys/stat.h>int main(int agrc , char* argv[])
{struct stat sbuf ; int ret = stat(argv[1] , &sbuf);if(ret == -1){perror("stat error");exit(1);}printf("file size:%ld\n" , sbuf.st_size);return 0;
}

区别:stat会穿透符号链接,也就是软连接 ,输出的是原始,而不是输出符号链接, lstat不会

link函数/unlink函数

可以实现mv功能

unlink函数特征:并不是调完删除文件就没了,而是要等到所有打开该文件的进程关闭该文件,系统才会挑时间释放。

文件、目录权限

实现ls

DIR* opendir(char *name):

int closedir(DIR* dp)

struct dirent *readdir(DIR* dp)

struct dirent{五种主要记住两种  inode,char name[255]};


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<pthread.h>
#include<dirent.h>int main(int argc , char *argv[])
{DIR *dp;struct dirent *sdp;dp = opendir(argv[1]);if(dp==NULL){perror("opendir error");exit(1);}while((sdp = readdir(dp))!=NULL){printf("%s\t" , sdp->d_name);};printf("\n");closedir(dp);return 0 ;
}

http://www.dtcms.com/wzjs/391009.html

相关文章:

  • 怎么做祝福网站搜索引擎营销的主要方式有哪些?
  • 网站建设商城商城网站建设多少钱想做个网络推广
  • 做cpa推广的网站怎么弄最近新闻有哪些
  • 网站开发前调查电子商务seo是什么意思
  • dw8 php做购物网站教程计算机基础培训机构
  • 企业网站应该怎么做百度移动端排名软件
  • 做网站怎么添加图片网络运营培训
  • 把域名解析到其他网站的ip地址叫交换链接是什么
  • 网站备案成功后可以改吗seo算法入门教程
  • 不断完善政府网站建设企业整站seo
  • 泉州网站建设方案优化网站优化和网站推广
  • 做网站在图片里加文字怎么给自己的公司做网站
  • 购物网站中加减数目的怎么做长春seo公司
  • 光泽县规划建设局网站贺州seo
  • 太湖县城乡建设局网站app推广注册从哪里接单
  • 租用空间做网站百度风云榜排行榜
  • wordpress安装在本地安装seo公司网站
  • 八爷源码网北京seoqq群
  • 深圳医疗网站建设公司的磁力搜索引擎
  • 献县网站seo外链工具软件
  • 西安百度推广运营公司广东网站se0优化公司
  • cms优秀网站设计案例湖南网站推广优化
  • 网帆网站建设怀化网站seo
  • 怎么判断公司是不是外包自己怎么给网站做优化排名
  • 镇江做网站要多少钱肇庆网站建设
  • 每一个网站都要后台吗推广策划方案怎么写
  • owasp+网站开发广告软文案例
  • 沧州做网站多少钱东莞疫情最新数据
  • 网站建设书电子商务说白了就是干什么的
  • 南充 网站开发深圳网络推广的公司