summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1996-04-23 11:47:16 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1996-04-23 11:47:16 +0000
commitc3c7766f7bf376c4c1517a5fe7997dddb047620c (patch)
treea603e179a3b11fe5de8c81e8a34e80b4abe97a48 /lib
parent62091e720387d30e8e1ed6cd024ee846fd0077b2 (diff)
do not assume "." exists -- it might have gotten unlink()'ed -- we
don't want closedir() to SIGSEGV. as well, sample code in man pages should be very robust and not hint that closedir() might survive being passed opendir()'s failure code.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/directory.314
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/libc/gen/directory.3 b/lib/libc/gen/directory.3
index 4cd377abe7d..15bf5c1e952 100644
--- a/lib/libc/gen/directory.3
+++ b/lib/libc/gen/directory.3
@@ -157,12 +157,14 @@ Sample code which searchs 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)) {
- (void)closedir(dirp);
- return FOUND;
- }
-(void)closedir(dirp);
+if (dirp) {
+ while ((dp = readdir(dirp)) != NULL)
+ if (dp->d_namlen == len && !strcmp(dp->d_name, name)) {
+ (void)closedir(dirp);
+ return FOUND;
+ }
+ (void)closedir(dirp);
+}
return NOT_FOUND;
.Ed
.Sh SEE ALSO