Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/gen - move a example into EXAMPLES section.



details:   https://anonhg.NetBSD.org/src/rev/c26744728423
branches:  trunk
changeset: 535092:c26744728423
user:      yamt <yamt%NetBSD.org@localhost>
date:      Sat Aug 10 02:55:20 2002 +0000

description:
- move a example into EXAMPLES section.
- check a return value of opendir.
from openbsd.

diffstat:

 lib/libc/gen/directory.3 |  24 ++++++++++++++----------
 1 files changed, 14 insertions(+), 10 deletions(-)

diffs (41 lines):

diff -r e7182cabec7b -r c26744728423 lib/libc/gen/directory.3
--- a/lib/libc/gen/directory.3  Sat Aug 10 02:41:21 2002 +0000
+++ b/lib/libc/gen/directory.3  Sat Aug 10 02:55:20 2002 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: directory.3,v 1.15 2002/04/29 01:41:43 simonb Exp $
+.\"    $NetBSD: directory.3,v 1.16 2002/08/10 02:55:20 yamt Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -153,18 +153,22 @@
 .Em directory stream ,
 see
 .Xr open 2 .
-.Pp
-Sample code which searchs a directory for entry ``name'' is:
+.Sh EXAMPLES
+Sample code which searches a directory for entry
+.Dq name
+is:
 .Bd -literal -offset indent
 len = strlen(name);
 dirp = opendir(".");
-while ((dp = readdir(dirp)) != NULL)
-       if (dp-\*[Gt]d_namlen == len \*[Am]\*[Am] !strcmp(dp-\*[Gt]d_name, name)) {
-               (void)closedir(dirp);
-               return FOUND;
-       }
-(void)closedir(dirp);
-return NOT_FOUND;
+if (dirp) {
+       while ((dp = readdir(dirp)) != NULL)
+               if (dp-\*[Gt]d_namlen == len \*[Am]\*[Am] !strcmp(dp-\*[Gt]d_name, name)) {
+                       (void)closedir(dirp);
+                       return (FOUND);
+               }
+       (void)closedir(dirp);
+}
+return (NOT_FOUND);
 .Ed
 .Sh SEE ALSO
 .Xr close 2 ,



Home | Main Index | Thread Index | Old Index