aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Kerrisk <mtk.manpages@gmail.com>2012-07-07 07:40:07 +0200
committerMichael Kerrisk <mtk.manpages@gmail.com>2012-07-19 12:51:28 +0200
commiteb059156a760545b5f474930003c7fc535bda1ab (patch)
treede4c388675c38dc6e0809449a90736dd0a724e00
parent02ff975dc79eeecbac17e8e7934bae54315dc757 (diff)
downloadman-pages-eb059156a760545b5f474930003c7fc535bda1ab.tar.gz
readdir.3: Handle -1 error from pathconf() in example code snippet
Improve the example demonstrating allocation of a buffer for readdir_r() to handle -1 error return from pathconf(). Otherwise, naive readers may think that pathconf() return value can be used without checking. Reported-by: Jan Engelhardt <jengelh@inai.de> Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
-rw-r--r--man3/readdir.38
1 files changed, 5 insertions, 3 deletions
diff --git a/man3/readdir.3 b/man3/readdir.3
index 1811a95339..0660efded5 100644
--- a/man3/readdir.3
+++ b/man3/readdir.3
@@ -31,7 +31,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
@@ -226,8 +226,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