Follow style(9) in example code and handle opendir(3) error.
This commit is contained in:
parent
8c98d9bae1
commit
32981eb31b
@ -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 ,
|
||||
|
Loading…
Reference in New Issue
Block a user