diff options
author | pjd <pjd@FreeBSD.org> | 2011-03-26 07:15:57 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2011-03-26 07:15:57 +0000 |
commit | 5cdf4e6f59745010af06545c1942d47da5dd3764 (patch) | |
tree | 9ee9819a88620d854f261f50a3259a3697a8d8af /lib | |
parent | 45abd9f4f2a3b66e2e11d17eb317e554b3211f42 (diff) | |
download | FreeBSD-src-5cdf4e6f59745010af06545c1942d47da5dd3764.zip FreeBSD-src-5cdf4e6f59745010af06545c1942d47da5dd3764.tar.gz |
Follow style(9) in example code and handle opendir(3) error.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/directory.3 | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/libc/gen/directory.3 b/lib/libc/gen/directory.3 index 3be3fa8..e6d8798 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 , |