1. 标准 C 库 IO 函数2. 标准 C 库 IO 和 Linux 系统 IO 的关系3. 相关概念4. Linux 系统 IO 操作
1. 标准 C 库 IO 函数2. 标准 C 库 IO 和 Linux 系统 IO 的关系man 3 fread 查看函数用法
3. 相关概念C 库 IO 调用 Linux 系统 IO, 如 fopen标准库函数调用open系统调用
虚拟地址空间
文件描述符
st_mode 变量
Linux 下文件类型有哪些?
| 文件类型 | 文件类型标识 | d_type |
|---|---|---|
| 普通文件 | - | DT_REG |
| 目录文件 | d | DT_DIR |
| 符号链接 | l | DT_LNK |
| 字符设备 | c | DT_CHR |
| 块设备 | b | DT_BLK |
| 管道 | p | DT_FIFO |
| 套接字 | s | DT_SOCK |
| 未知 | DT_UNKNOWN |
man 2 open 查看open函数帮助
open/ close
#include#include #include // 打开一个已经存在的文件 int open(const char *pathname, int flags); #include void perror(const char *s); // 创建一个新的文件 int open(const char *pathname, int flags, mode_t mode); // 关闭一个文件描述符 #include int close(int fd);
read/ write
#includessize_t read(int fd, void *buf, size_t count); #include ssize_t write(int fd, const void *buf, size_t count);
lseek
// 标准C库的函数 #includeint fseek(FILE *stream, long offset, int whence); // Linux系统函数 #include #include off_t lseek(int fd, off_t offset, int whence);
stat/ lstat
#include#include #include int stat(const char *pathname, struct stat *statbuf); int lstat(const char *pathname, struct stat *statbuf);
文件属性操作函数
//文件属性操作函数 #includeint access(const char *pathname, int mode); #include int chmod(const char *pathname, mode_t mode); #include #include int truncate(const char *path, off_t length); #include int chown(const char *pathname, uid_t owner, gid_t group);
目录操作函数
#includeint rename(const char *oldpath, const char *newpath); #include #include int mkdir(const char *pathname, mode_t mode); #include int chdir(const char *path); #include char *getcwd(char *buf, size_t size); #include int rmdir(const char *pathname); // 读取目录中的数据 #include struct dirent *readdir(DIR *dirp); // 关闭目录 #include #include int closedir(DIR *dirp);
dup/ dup2/ fcntl
#includeint dup(int oldfd); #include int dup2(int oldfd, int newfd); #include #include int fcntl(int fd, int cmd, ...);



