Linux文件:
用文件描述符号 绑定 一个文件
文件描述符号: File Describe 简称 fd 本质是个整数
操作系统内核会维护这个整数,把它和硬盘中的一个文件联系在一起,互为映射
标准fd
0 标准输入 stdin
1 标准输出 stdout
2 标准错误输出 stderror
都是终端设备
lseek 挪文件内容指针
SEEK_SET 文件头
SEEK_END 文件尾
SEEK_CUR 当前位置
头文件有点多,不过不用管,毕竟一口气全复制过去以后用啥直接就能用不用再考虑头文件
#include <stdio.h>
#include <unistd.h> //linux操作系统标准头文件
#include <string.h> //memcpy
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h> //umask
#include <time.h>
#include <sys/time.h>
#include <dirent.h> //遍历目录
#include <fcntl.h> //文件映射虚拟内存
#include <sys/mman.h>
#include <wait.h>
#include <signal.h> //SIGCHLD
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/select.h>
void writeFile(int argc, char *argv[])
{
if (argc < 2)
{
printf("请命令行输入文件名\n");
exit(-1);
}
int fd = open(argv[1], O_WRONLY);
if (-1 == fd)
{