栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

IO函数 (C库 VS Linux文件系统)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

IO函数 (C库 VS Linux文件系统)

文章目录

1. 标准 C 库 IO 函数2. 标准 C 库 IO 和 Linux 系统 IO 的关系3. 相关概念4. Linux 系统 IO 操作

1. 标准 C 库 IO 函数

man 3 fread 查看函数用法

2. 标准 C 库 IO 和 Linux 系统 IO 的关系

C 库 IO 调用 Linux 系统 IO, 如 fopen标准库函数调用open系统调用

3. 相关概念

    虚拟地址空间

    文件描述符

    st_mode 变量

    Linux 下文件类型有哪些?

文件类型文件类型标识d_type
普通文件-DT_REG
目录文件dDT_DIR
符号链接lDT_LNK
字符设备cDT_CHR
块设备bDT_BLK
管道pDT_FIFO
套接字sDT_SOCK
未知DT_UNKNOWN
4. Linux 系统 IO 操作

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

    #include 
    ssize_t read(int fd, void *buf, size_t count);
    
    
    #include 
    ssize_t write(int fd, const void *buf, size_t count);
    
    

    lseek

    // 标准C库的函数
    #include 
    int 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);

    文件属性操作函数

    //文件属性操作函数
    
    #include 
    int 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);
    
    

    目录操作函数

    #include 
    int 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

      #include 
      int dup(int oldfd);
      
      
      
      #include 
      int dup2(int oldfd, int newfd);
      
      
      
      #include 
      #include 
      int fcntl(int fd, int cmd, ...);
      
      
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/784470.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号