Chinaunix首页 | 论坛 | 博客
  • 博客访问: 276530
  • 博文数量: 28
  • 博客积分: 690
  • 博客等级: 上士
  • 技术积分: 358
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-25 20:39
文章分类

全部博文(28)

文章存档

2012年(12)

2011年(16)

分类: C/C++

2012-08-26 10:03:06

头文件:
#include
#include

opendir():
函数原型:
DIR * opendir(const char* path);
打开一个目录,在失败的时候返回NULL(如果path对应的是文件,则返回NULL)
DIR 结构体的原型为:struct_dirstream

       在linux系统中:

        typedef struct __dirstream 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.   */
        };



readdir():
函数原型:
struct dirent * readdir(DIR * dir_handle);
本函数读取dir_handle目录下的目录项,如果有未读取的目录项,返回目录项,否则返回NULL。
循环读取dir_handle,目录和文件都读

       返回dirent结构体指针,dirent结构体成员如下,(文件和目录都读)

  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字符 */

  }



closedir():
函数原型:
int closedir(DIR * dir_handle);



阅读(25631) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~