OSDN Git Service

(split) LDP v3.30, v3.31 の定型的な変更内容を反映。
[linuxjm/LDP_man-pages.git] / release / man3 / readdir.3
1 .\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" References consulted:
24 .\"     Linux libc source code
25 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26 .\"     386BSD man pages
27 .\" Modified Sat Jul 24 16:09:49 1993 by Rik Faith (faith@cs.unc.edu)
28 .\" Modified 11 June 1995 by Andries Brouwer (aeb@cwi.nl)
29 .\" Modified 22 July 1996 by Andries Brouwer (aeb@cwi.nl)
30 .\" 2007-07-30 Ulrich Drepper <drepper@redhat.com>, mtk:
31 .\"     Rework discussion of nonstandard structure fields.
32 .\" 2008-09-11, mtk, Document readdir_r().
33 .\"
34 .\" Japanese Version Copyright (c) 1997 HIROFUMI Nishizuka
35 .\"     all rights reserved.
36 .\" Translated 1997-12-24, HIROFUMI Nishizuka <nishi@rpts.cl.nec.co.jp>
37 .\" Updated & Modified 2002-03-24, Yuichi SATO <ysato@h4.dion.ne.jp>
38 .\" Updated & Modified 2005-01-16, Yuichi SATO <ysato444@yahoo.co.jp>
39 .\" Updated & Modified 2005-09-06, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
40 .\" Updated 2008-08-11, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.05
41 .\"
42 .TH READDIR 3  2010-09-10 "" "Linux Programmer's Manual"
43 .SH Ì¾Á°
44 readdir, readdir_r \- ¥Ç¥£¥ì¥¯¥È¥ê¤òÆɤ߹þ¤à
45 .SH ½ñ¼°
46 .nf
47 .B #include <dirent.h>
48 .sp
49 .BI "struct dirent *readdir(DIR *" dirp );
50 .sp
51 .BI "int readdir_r(DIR *" dirp ", struct dirent *" entry \
52 ", struct dirent **" result );
53 .fi
54 .sp
55 .in -4n
56 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
57 .RB ( feature_test_macros (7)
58 »²¾È):
59 .ad l
60 .in
61 .sp
62 .BR readdir_r ():
63 .RS 4
64 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _BSD_SOURCE ||
65 _SVID_SOURCE || _POSIX_SOURCE
66 .RE
67 .ad b
68 .SH ÀâÌÀ
69 .BR readdir ()
70 ´Ø¿ô¤Ï¡¢\fIdirp\fP ¤¬»Ø¤¹¥Ç¥£¥ì¥¯¥È¥ê¥¹¥È¥ê¡¼¥à¤ÎÃæ¤Ç¡¢
71 ¼¡¤Î¥Ç¥£¥ì¥¯¥È¥ê¥¨¥ó¥È¥ê¤òɽ¤¹ \fIdirent\fP ¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤òÊÖ¤¹¡£
72 ¥Ç¥£¥ì¥¯¥È¥ê¥¹¥È¥ê¡¼¥à¤ÎËöÈø¤Ë㤷¤¿¾ì¹ç¤ä¡¢
73 ¥¨¥é¡¼¤¬È¯À¸¤·¤¿¾ì¹ç¤Ï¡¢ NULL ¤òÊÖ¤¹¡£
74 .PP
75 Linux ¤Ç¤Ï
76 .I dirent
77 ¹½Â¤ÂΤϰʲ¼¤Î¤è¤¦¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£
78 .PP
79 .in +4n
80 .nf
81 struct dirent {
82     ino_t          d_ino;       /* inode ÈÖ¹æ */
83     off_t          d_off;       /* ¼¡¤Î dirent ¤Ø¤Î¥ª¥Õ¥»¥Ã¥È */
84     unsigned short d_reclen;    /* ¤³¤Î¥ì¥³¡¼¥É¤ÎŤµ */
85     unsigned char  d_type;      /* ¥Õ¥¡¥¤¥ë¼ïÊÌ¡£Á´¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à */
86                                    ¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¤ï¤±¤Ç¤Ï¤Ê¤¤ */
87     char           d_name[256]; /* ¥Õ¥¡¥¤¥ë̾ */
88 };
89 .fi
90 .in
91 .PP
92 .I dirent
93 ¹½Â¤ÂΤΥե£¡¼¥ë¥É¤Ç POSIX.1 ¤ÇÍ׵ᤵ¤ì¤Æ¤¤¤ë¤Î¤Ï¡¢
94 .IR d_name []
95 ¤È (XSI ³ÈÄ¥¤Ç¤Î)
96 .I d_ino
97 ¤À¤±¤Ç¤¢¤ë¡£
98 .IR d_name []
99 ¤Ï¤½¤ÎÂ礭¤µ¤âµ¬Äꤵ¤ì¤Æ¤ª¤é¤º¡¢
100 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤Ë¤ÏºÇÂç¤Ç
101 .B NAME_MAX
102 ¸Ä¤Îʸ»ú¤È¡¢¤½¤ì¤Ë³¤¯½ªÃ¼¤Î NULL ¥Ð¥¤¥È¤¬³ÊǼ¤µ¤ì¤ë¡£
103 ¾¤Î¥Õ¥£¡¼¥ë¥É¤ÏÈóɸ½à¤Ç¤¢¤ê¡¢Á´¤Æ¤Î¥·¥¹¥Æ¥à¤Ë¸ºß¤¹¤ë¤ï¤±¤Ç¤Ï¤Ê¤¤¡£
104 ¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï¡¢²¼µ­¤Î¡ÖÃí°Õ¡×¤ò»²¾È¤Î¤³¤È¡£
105 .PP
106 .BR readdir ()
107 ¤Ë¤è¤Ã¤ÆÊÖ¤µ¤ì¤ë¥Ç¡¼¥¿¤Ï¡¢¤½¤ì°Ê¹ß¤ÎƱ¤¸¥¹¥È¥ê¡¼¥à¤ËÂФ¹¤ë
108 .BR readdir ()
109 ¤Î¸Æ¤Ó½Ð¤·¤Ë¤è¤Ã¤Æ¾å½ñ¤­¤µ¤ì¤ë²ÄǽÀ­¤¬¤¢¤ë¡£
110
111 .BR readdir_r ()
112 ´Ø¿ô¤Ï
113 .BR readdir ()
114 ¤Î¥ê¥¨¥ó¥È¥é¥ó¥ÈÈǤǤ¢¤ë¡£
115 ¤³¤Î´Ø¿ô¤Ï¥Ç¥£¥ì¥¯¥È¥ê¥¹¥È¥ê¡¼¥à
116 .I dirp
117 ¤«¤é¼¡¤Î¥Ç¥£¥ì¥¯¥È¥ê¥¨¥ó¥È¥ê¤òÆɤ߹þ¤ß¡¢
118 .I entry
119 ¤¬»Ø¤¹¸Æ¤Ó½Ð¤·¸µ¤¬³ä¤êÅö¤Æ¤¿¥Ð¥Ã¥Õ¥¡¤Ë¤½¤Î¥¨¥ó¥È¥ê¤ò³ÊǼ¤·¤ÆÊÖ¤¹
120 (¤³¤Î¥Ð¥Ã¥Õ¥¡¤Î³ä¤êÅö¤Æ¤Ë¤Ä¤¤¤Æ¤Ï¡ÖÃí°Õ¡×¤ÎÀá¤ò»²¾È¤Î¤³¤È)¡£
121 ÊÖ¤µ¤ì¤ë¥¨¥ó¥È¥ê¤Ø¤Î¥Ý¥¤¥ó¥¿¤¬
122 .I *result
123 ¤Ë³ÊǼ¤µ¤ì¤ë¡£¥Ç¥£¥ì¥¯¥È¥ê¥¹¥È¥ê¡¼¥à¤ÎËöÈø¤Ë㤷¤¿¾ì¹ç¤Ï¡¢
124 NULL ¤¬
125 .I *result
126 ¤Ë³ÊǼ¤µ¤ì¤ë¡£
127 .SH ÊÖ¤êÃÍ
128 À®¸ù¤¹¤ë¤È¡¢
129 .BR readdir ()
130 ¤Ï
131 .I dirent
132 ¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤òÊÖ¤¹¡£
133 (¤³¤Î¹½Â¤ÂΤÏÀÅŪ¤Ë³ä¤êÅö¤Æ¤é¤ì¤Æ¤¤¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
134 ¤³¤Î¥Ý¥¤¥ó¥¿¤ò
135 .BR free (3)
136 ¤·¤è¤¦¤È¤·¤Ê¤¤¤³¤È¡£)
137 ¥Ç¥£¥ì¥¯¥È¥ê¥¹¥È¥ê¡¼¥à¤ÎËöÈø¤Ë㤷¤¿¾ì¹ç¤Ë¤Ï¡¢NULL ¤¬ÊÖ¤µ¤ì¡¢
138 .I errno
139 ¤ÏÊѲ½¤·¤Ê¤¤¡£
140 ¥¨¥é¡¼¤¬È¯À¸¤·¤¿¾ì¹ç¡¢NULL ¤¬ÊÖ¤µ¤ì¡¢
141 .I errno
142 ¤¬Å¬ÀÚ¤ËÀßÄꤵ¤ì¤ë¡£
143
144 À®¸ù¤¹¤ë¤È¡¢
145 .BR readdir_r ()
146 ´Ø¿ô¤Ï 0 ¤òÊÖ¤¹¡£
147 ¥¨¥é¡¼¤Î¾ì¹ç¡¢(¡Ö¥¨¥é¡¼¡×¤ÎÀá¤Î¥ê¥¹¥È¤ËºÜ¤Ã¤Æ¤¤¤ë) Àµ¤Î¥¨¥é¡¼ÈÖ¹æ¤òÊÖ¤¹¡£
148 ¥Ç¥£¥ì¥¯¥È¥ê¥¹¥È¥ê¡¼¥à¤ÎËöÈø¤Ë㤷¤¿¾ì¹ç¡¢
149 .BR readdir_r ()
150 ¤ÏÊÖ¤êÃͤȤ·¤Æ 0 ¤òÊÖ¤·¡¢
151 .I *result
152 ¤Ë NULL ¤ò³ÊǼ¤¹¤ë¡£
153 .SH ¥¨¥é¡¼
154 .TP
155 .B EBADF
156 ¥Ç¥£¥ì¥¯¥È¥ê¥¹¥È¥ê¡¼¥à¥Ç¥£¥¹¥¯¥ê¥×¥¿ \fIdirp\fP ¤¬Ìµ¸ú¡£
157 .SH ½àµò
158 SVr4, 4.3BSD, POSIX.1-2001.
159 .SH Ãí°Õ
160 ¥Õ¥£¡¼¥ë¥É
161 .I d_name
162 ¤È
163 .I d_ino
164 ¤À¤±¤¬ POSIX.1-2001 ¤Çµ¬Äꤵ¤ì¤Æ¤¤¤ë¡£
165 »Ä¤ê¤Î¥Õ¥£¡¼¥ë¥É¤Ï¿¤¯¤Î¥·¥¹¥Æ¥à¤Ë¸ºß¤¹¤ë¤¬¡¢Á´¤Æ¤Î¥·¥¹¥Æ¥à¤Ë
166 ¸ºß¤¹¤ë¤ï¤±¤Ç¤Ï¤Ê¤¤¡£
167 glibc ¤Ç¤Ï¡¢¥×¥í¥°¥é¥à¤¬ POSIX.1 ¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¥Õ¥£¡¼¥ë¥É¤¬
168 ÍøÍѤǤ­¤ë¤«¤ò¥Á¥§¥Ã¥¯¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
169 ¥Á¥§¥Ã¥¯¤¹¤ë¤Ë¤Ï¡¢¥Þ¥¯¥í
170 .BR _DIRENT_HAVE_D_NAMLEN ,
171 .BR _DIRENT_HAVE_D_RECLEN ,
172 .BR _DIRENT_HAVE_D_OFF ,
173 .B _DIRENT_HAVE_D_TYPE
174 ¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤«¤ò¥Æ¥¹¥È¤¹¤ì¤Ð¤è¤¤¡£
175
176 .I d_type
177 ¥Õ¥£¡¼¥ë¥É¤Ï¡¢Linux °Ê³°¤Ç¤Ï¡¢
178 ¼ç¤Ë BSD ·Ï¤Î¥·¥¹¥Æ¥à¤Ë¤À¤±Â¸ºß¤¹¤ë¡£
179 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤ò»È¤¦¤È¡¢
180 ¤½¤Î¸å¤ÎÆ°ºî¤¬¥Õ¥¡¥¤¥ë¤Î¼ïÊ̤ˤè¤ê·è¤Þ¤ë¾ì¹ç¤Ë¡¢
181 .BR lstat (2)
182 ¤ò¸Æ¤Ó½Ð¤¹¥³¥¹¥È¤òÈò¤±¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
183 µ¡Ç½¸¡ºº¥Þ¥¯¥í
184 .B _BSD_SOURCE
185 ¤¬ÄêµÁ¤µ¤ì¤¿¾ì¹ç¡¢glibc ¤Ï
186 .I d_type
187 ¤ÇÊÖ¤µ¤ì¤ëÃͤȤ·¤Æ°Ê²¼¤Î¥Þ¥¯¥íÄê¿ô¤òÄêµÁ¤¹¤ë¡£
188 .TP 12
189 .B DT_BLK
190 ¥Ö¥í¥Ã¥¯¡¦¥Ç¥Ð¥¤¥¹¤Ç¤¢¤ë¡£
191 .TP
192 .B DT_CHR
193 ¥­¥ã¥é¥¯¥¿¡¦¥Ç¥Ð¥¤¥¹¤Ç¤¢¤ë¡£
194 .TP
195 .B DT_DIR
196 ¥Ç¥£¥ì¥¯¥È¥ê¤Ç¤¢¤ë¡£
197 .TP
198 .B DT_FIFO
199 ̾Á°ÉÕ¤­¥Ñ¥¤¥× (FIFO) ¤Ç¤¢¤ë¡£
200 .TP
201 .B DT_LNK
202 ¥·¥ó¥Ü¥ê¥Ã¥¯¡¦¥ê¥ó¥¯¤Ç¤¢¤ë¡£
203 .TP
204 .B DT_REG
205 Ä̾ï¤Î¥Õ¥¡¥¤¥ë¤Ç¤¢¤ë¡£
206 .TP
207 .B DT_SOCK
208 UNIX ¥É¥á¥¤¥ó¥½¥±¥Ã¥È¤Ç¤¢¤ë¡£
209 .TP
210 .B DT_UNKNOWN
211 ¥Õ¥¡¥¤¥ë¥¿¥¤¥×¤¬ÉÔÌÀ¤Ç¤¢¤ë¡£
212 .\" The glibc manual says that on some systems this is the only
213 .\" value returned
214 .PP
215 ¥Õ¥¡¥¤¥ë¼ïÊ̤ò·èÄê¤Ç¤­¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¤Ï¡¢
216 .I d_type
217 ¤Ë
218 .B DT_UNKNOWN
219 ¤¬Æþ¤ë¡£
220
221 ¸½ºß¤Î¤È¤³¤í¡¢
222 .\" ¥«¡¼¥Í¥ë 2.6.27
223 .\" Æ±¤¸ÀâÌÀʸ¤¬ readdir.2 ¤Ë¤â¤¢¤ë¡£
224 .I d_type
225 ¤Ç¥Õ¥¡¥¤¥ë¥¿¥¤¥×¤òÊÖ¤¹µ¡Ç½¤¬´°Á´¤Ë¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¤Î¤Ï¡¢
226 ¤¤¤¯¤Ä¤«¤Î¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤Ë¤ª¤¤¤Æ¤Î¤ß¤Ç¤¢¤ë
227 (Btrfs, ext2, ext3, ext4 ¤Ï¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë)¡£
228 ¤É¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤â¡¢
229 .B DT_UNKNOWN
230 ¤¬ÊÖ¤µ¤ì¤¿ºÝ¤ËŬÀڤ˽èÍý¤Ç¤­¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
231
232 POSIX.1 ¤Ç¤Ï
233 .I d_name
234 ¥Õ¥£¡¼¥ë¥É¤Î¥µ¥¤¥º¤Ïµ¬Äꤵ¤ì¤Æ¤ª¤é¤º¡¢
235 .I dirent
236 ¹½Â¤ÂΤÎ
237 .I d_name
238 ¤Î¸å¤í¤Ë¾¤ÎÈóɸ½à¤Î¥Õ¥£¡¼¥ë¥É¤¬¤¢¤ë¤«¤â¤·¤ì¤Ê¤¤¤Î¤Ç¡¢
239 °Ü¿¢À­¤¬É¬Íפʥ¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç
240 .BR readdir_r ()
241 ¤ò»È¤¦¾ì¹ç¤Ï
242 .I entry
243 ¤ËÅϤ¹¥Ð¥Ã¥Õ¥¡¤ò¼¡¤Î¤è¤¦¤Ë¤·¤Æ³ä¤êÅö¤Æ¤ë¤Ù¤­¤Ç¤¢¤ë¡£
244 .in +4n
245 .nf
246
247 len = offsetof(struct dirent, d_name) +
248           pathconf(dirpath, _PC_NAME_MAX) + 1
249 entryp = malloc(len);
250
251 .fi
252 .in
253 (POSIX.1 ¤Ç¤Ï
254 .I "struct dirent"
255 ¤ÎºÇ¸å¤Î¥Õ¥£¡¼¥ë¥É¤¬
256 .I d_name
257 ¤Ç¤¢¤ë¤³¤È¤òÍ׵ᤷ¤Æ¤¤¤ë¡£)
258 .SH ´ØÏ¢¹àÌÜ
259 .BR getdents (2),
260 .BR read (2),
261 .BR closedir (3),
262 .BR dirfd (3),
263 .BR ftw (3),
264 .BR offsetof (3),
265 .BR opendir (3),
266 .BR rewinddir (3),
267 .BR scandir (3),
268 .BR seekdir (3),
269 .BR telldir (3)