.\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
.\"
+.\" %%%LICENSE_START(VERBATIM)
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
+.\" %%%LICENSE_END
.\"
.\" References consulted:
.\" Linux libc source code
.\" This file was generated with po4a. Translate the source file.
.\"
.\"*******************************************************************
-.TH READDIR 3 2010\-09\-10 "" "Linux Programmer's Manual"
+.TH READDIR 3 2013\-03\-24 "" "Linux Programmer's Manual"
.SH 名前
readdir, readdir_r \- ディレクトリを読み込む
.SH 書式
.nf
struct dirent {
ino_t d_ino; /* inode 番号 */
- off_t d_off; /* 次の dirent へのオフセット */
+ off_t d_off; /* オフセットではない; 注意を参照 */
unsigned short d_reclen; /* このレコードの長さ */
unsigned char d_type; /* ファイル種別。全ファイルシステム */
でサポートされているわけではない */
\fB_DIRENT_HAVE_D_RECLEN\fP, \fB_DIRENT_HAVE_D_OFF\fP, \fB_DIRENT_HAVE_D_TYPE\fP
が定義されているかをテストすればよい。
+.\" https://lwn.net/Articles/544298/
+The value returned in \fId_off\fP is the same as would be returned by calling
+\fBtelldir\fP(3) at the current position in the directory stream. Be aware
+that despite its type and name, the \fId_off\fP field is seldom any kind of
+directory offset on modern file systems. Applications should treat this
+field as an opaque value, making no assumptions about its contents; see also
+\fBtelldir\fP(3).
+
\fId_type\fP フィールドは、Linux 以外では、 主に BSD 系のシステムにだけ存在する。 このフィールドを使うと、
その後の動作がファイルの種別により決まる場合に、 \fBlstat\fP(2) を呼び出すコストを避けることができる。 機能検査マクロ
\fB_BSD_SOURCE\fP が定義された場合、glibc は \fId_type\fP で返される値として以下のマクロ定数を定義する。
.in +4n
.nf
-len = offsetof(struct dirent, d_name) +
- pathconf(dirpath, _PC_NAME_MAX) + 1
+name_max = pathconf(dirpath, _PC_NAME_MAX);
+if (name_max == \-1) /* 上限が定義されていない、またはエラー */
+ name_max = 255; /* 適当な値を入れる */
+len = offsetof(struct dirent, d_name) + name_max + 1;
entryp = malloc(len);
.fi
\fBoffsetof\fP(3), \fBopendir\fP(3), \fBrewinddir\fP(3), \fBscandir\fP(3),
\fBseekdir\fP(3), \fBtelldir\fP(3)
.SH この文書について
-この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.41 の一部
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.51 の一部
である。プロジェクトの説明とバグ報告に関する情報は
http://www.kernel.org/doc/man\-pages/ に書かれている。