zoukankan      html  css  js  c++  java
  • dir

    struct dirent 与 DIR

    1.存储目录中的文件信息(文件名、扩展名等等)

    #include <dirent.h>
    struct dirent
    {
       long d_ino; /* inode number 索引节点号 */
       off_t d_off; /* offset to this dirent 在目录文件中的偏移 */
       unsigned short d_reclen; /* length of this d_name 文件名长 */
       unsigned char d_type; /* the type of d_name 文件类型 */
       char d_name [NAME_MAX+1]; /* file name (null-terminated) 文件名,最长255字符 */
    }
     
    2.
    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.   */
       };

    typedef struct __dirstream DIR;
     
     
     

    telldir()与seekdir()

    范例
    #include <sys/types.h>
    #include <dirent.h>
    #include <unistd.h>
    main()
    {
        DIR * dir;
        struct dirent * ptr;
        int offset, offset_5, i = 0;
        dir = opendir("/etc/rc.d");  // opendir
        while((ptr = readdir(dir)) != NULL)
        {
            offset = telldir(dir);
            if(++i == 5)
            offset_5 = offset;
            printf("d_name : %s offset :%d ", ptr->d_name, offset);
        }
        seekdir(dir offset_5);
        printf("Readdir again! ");

        while((ptr = readdir(dir)) != NULL)
        {
            offset = telldir(dir);
            printf("d_name : %s offset :%d ", ptr->d_name, offset);
        }
        closedir(dir);
    }

    执行:
    d_name : . offset :12
    d_name : .. offset :24
    d_name : init.d offset 40
    d_name : rc0.d offset :56
    d_name : rc1.d offset :72
    d_name : rc2.d offset :88
    d_name : rc3.d offset :104
    d_name : rc4.d offset :120
    d_name : rc5.d offset :136
    d_name : rc6.d offset :152
    d_name : rc offset :164
    d_name : rc.local offset :180
    d_name : rc.sysinit offset :4096 readdir again!
    d_name : rc2.d offset :88
    d_name : rc3.d offset :104
    d_name : rc4.d offset :120
    d_name : rc5.d offset :136
    d_name : rc6.d offset :152
    d_name : rc offset :164
    d_name : rc.local offset :180
    d_name : rc.sysinit offset :4096

  • 相关阅读:
    php $_SERVER 中的 QUERY_STRING和REQUEST_URI
    php 弱类型比较
    php函数漏洞
    web源码泄露
    sqlmap 基本使用步骤(一)
    php 调用远程url
    $_POST 和 php://input 的区别
    poj 3461 Oulipo (KMP入门)
    hdu 5417 Victor and Machine
    HDU 1885 Key Task (bfs)
  • 原文地址:https://www.cnblogs.com/banwhui/p/4595882.html
Copyright © 2011-2022 走看看