zoukankan      html  css  js  c++  java
  • opendir,readdir,closedir

     结构体dirent:

    struct dirent
    {
        ino_t    d_ino;  //inode number
        off_t        d_off;    //offset to the next diret
        unsigned short d_reclen;    //length of this record
        unsigned short d_type;        //type of file
        char         d_name[256];    //filename
    }

    结构体DIR

    struct __dirstream{
        void *__fd;                /* `struct hurd_fd' pointer for descriptor.   */
        char *__data;            /* Directory block.   */
        int __entry_data;    /* Entry number `__data' corresponds to.   */
        char *__ptr;               /* Current pointer into the block.   */
        int __entry_ptr;        /* Entry number `__ptr' corresponds to.   */
        size_t __allocation;      /* Space allocated for the block.   */
        size_t __size;                /* Total valid data in the block.   */
        __libc_lock_define (, __lock)          /* Mutex lock for this structure.   */
    } DIR;

    opendir函数

    #include<diret.h>
    DIR* opendir(const char *path)

    打开一个目录,在失败的时候返回一个空指针

    opendir函数打开一个与给定名的目录名name相对应的目录流,并返回一个指向该目录流的指针。打开后,该目录流指向了目录中的第一个目录项。若打开成功,则返回指向目录流的指针打开失败,返回NULL,并设置相应的错误代码errno

    readdir函数

    struct dirent *readdir(DIR *dir)

    readdir函数返回一个指向dirent结构体的指针,该结构体代表了由dir指向的目录流中的下一个目录项;如果读到end-of-file或者出现错误,那么返回NULL。

    该函数返回的值会被后续调用的(针对同一目录流)readdir函数返回值所覆盖

    函数调用成功会返回一个指向dirent结构体的指针,失败时或读到end-of-life时,返回NULL,并且设置相应的错误代码errno。

    closedir函数

    int closedir(DIR *dir);

    closedir函数关闭与指针dir相联系的目录流,关闭后目录流描述符dir不可再用。函数成功时返回0,失败时返回-1并设置了相应的错误代码errno

    chdir、fchdir函数

    int chdir(const char *path)
    int fchdir(int fd)

    chdir函数改变当前的工作目录位path指定的目录。

    fchdir函数和chdir功能一样,唯一的区别就是fchdir所改变的工作目录由打开的文件描述符所指定。

  • 相关阅读:
    c++ 在window下创建窗口的基本步骤
    visual studio 2015 安装MSDN全称Microsoft Developer Network 安装离线的MSDN
    interp1一维数据插值在matlab中的用法
    Win32控制台、Win32项目、MFC项目、CLR控制台、CLR空项目、空项目区别
    C# 中的延时的方法。
    C#入门——Console.Write()与Console.WriteLine()
    php发送短信验证码
    来自联想、百度的团队,带着颠覆的理想,做短信服务平台
    python发送短信验证码
    uperTextView-从未如此惊艳!一个超级的TextView
  • 原文地址:https://www.cnblogs.com/wanghao-boke/p/11599695.html
Copyright © 2011-2022 走看看