aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Jakub Dawidek <pjd@FreeBSD.org>2011-03-26 07:15:57 +0000
committerPawel Jakub Dawidek <pjd@FreeBSD.org>2011-03-26 07:15:57 +0000
commit32981eb31b5cd112d69c57cc14b1128eab0479c4 (patch)
tree9ee9819a88620d854f261f50a3259a3697a8d8af
parent8c98d9bae1fde5b88eb813abeaeb4a06735133ae (diff)
Notes
-rw-r--r--lib/libc/gen/directory.311
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/libc/gen/directory.3 b/lib/libc/gen/directory.3
index 3be3fa894fc3..e6d8798e7fb2 100644
--- a/lib/libc/gen/directory.3
+++ b/lib/libc/gen/directory.3
@@ -209,13 +209,16 @@ Sample code which searches a directory for entry ``name'' is:
.Bd -literal -offset indent
len = strlen(name);
dirp = opendir(".");
-while ((dp = readdir(dirp)) != NULL)
- if (dp->d_namlen == len && !strcmp(dp->d_name, name)) {
+if (dirp == NULL)
+ return (ERROR);
+while ((dp = readdir(dirp)) != NULL) {
+ if (dp->d_namlen == len && strcmp(dp->d_name, name) == 0) {
(void)closedir(dirp);
- return FOUND;
+ return (FOUND);
}
+}
(void)closedir(dirp);
-return NOT_FOUND;
+return (NOT_FOUND);
.Ed
.Sh SEE ALSO
.Xr close 2 ,