From 32981eb31b5cd112d69c57cc14b1128eab0479c4 Mon Sep 17 00:00:00 2001 From: Pawel Jakub Dawidek Date: Sat, 26 Mar 2011 07:15:57 +0000 Subject: [PATCH] Follow style(9) in example code and handle opendir(3) error. --- lib/libc/gen/directory.3 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/libc/gen/directory.3 b/lib/libc/gen/directory.3 index 3be3fa894fc..e6d8798e7fb 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 ,