OSDN Git Service

(split) LDP: Update original to LDP v3.50.
[linuxjm/LDP_man-pages.git] / original / man3 / readdir.3
index 1811a95..f7870fc 100644 (file)
@@ -1,5 +1,6 @@
 .\" 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.
@@ -19,6 +20,7 @@
 .\"
 .\" 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
@@ -31,7 +33,7 @@
 .\"     Rework discussion of nonstandard structure fields.
 .\" 2008-09-11, mtk, Document readdir_r().
 .\"
-.TH READDIR 3  2010-09-10 "" "Linux Programmer's Manual"
+.TH READDIR 3  2012-07-07 "" "Linux Programmer's Manual"
 .SH NAME
 readdir, readdir_r \- read a directory
 .SH SYNOPSIS
@@ -114,7 +116,7 @@ A pointer to the returned item is placed in
 if the end of the directory stream was encountered,
 then NULL is instead returned in
 .IR *result .
-.SH "RETURN VALUE"
+.SH RETURN VALUE
 On success,
 .BR readdir ()
 returns a pointer to a
@@ -142,7 +144,7 @@ returns 0, and returns NULL in
 .TP
 .B EBADF
 Invalid directory stream descriptor \fIdirp\fP.
-.SH "CONFORMING TO"
+.SH CONFORMING TO
 SVr4, 4.3BSD, POSIX.1-2001.
 .SH NOTES
 Only the fields
@@ -226,8 +228,10 @@ as follows:
 .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)         /* Limit not defined, or error */
+    name_max = 255;         /* Take a guess */
+len = offsetof(struct dirent, d_name) + name_max + 1;
 entryp = malloc(len);
 
 .fi
@@ -236,7 +240,7 @@ entryp = malloc(len);
 .I d_name
 is the last field in a
 .IR "struct dirent" .)
-.SH "SEE ALSO"
+.SH SEE ALSO
 .BR getdents (2),
 .BR read (2),
 .BR closedir (3),