rewinddir() - ディレクトリー・ストリームの先頭への位置変更

標準

標準/拡張機能 C/C++ 依存項目

POSIX.1
XPG4
XPG4.2
Single UNIX Specification、バージョン 3

両方  

形式

#define_POSIX_SOURCE
#include <dirent.h>

void rewinddir(DIR *dir);

機能説明

オープン・ディレクトリー・ストリームを先頭へと位置変更します。dir は、オープン・ディレクトリーと関連した DIR オブジェクト を指しています。

readdir() への次の呼び出しで、ディレクトリーの最初のエントリーが読み取 られます。ディレクトリーのオープン以後に、ディレクトリーの内容が変更されていた場合 には、rewinddir() への呼び出しで、ディレクトリー・ストリームが更新されるので、以降の readdir() で、新しい内容を読み取ることができます。

戻り値

rewinddir() は、値を戻しません。

CELEBR15
⁄* CELEBR15

   This example produces the contents of a directory by opening it,
   rewinding it, and closing it.

 *⁄
#define _POSIX_SOURCE
#include <dirent.h>
#include <errno.h>
#include <sys⁄types.h>
#undef _POSIX_SOURCE
#include <stdio.h>

main() {
  DIR *dir;
  struct dirent *entry;

  if ((dir = opendir("⁄")) == NULL)
    perror("opendir() error");
  else {
    puts("contents of root:");
    while ((entry = readdir(dir)) != NULL)
      printf("%s ", entry->d_name);
    rewinddir(dir);
    puts("");
    while ((entry = readdir(dir)) != NULL)
      printf("%s ", entry->d_name);
    closedir(dir);
    puts("");
  }
}
出力:
contents of root:
  . .. bin dev etc lib tmp u usr
  . .. bin dev etc lib tmp u usr

関連情報