Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 26 Mar 2011 07:15:57 +0000 (UTC)
From:      Pawel Jakub Dawidek <pjd@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r220023 - head/lib/libc/gen
Message-ID:  <201103260715.p2Q7FvDg006872@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pjd
Date: Sat Mar 26 07:15:57 2011
New Revision: 220023
URL: http://svn.freebsd.org/changeset/base/220023

Log:
  Follow style(9) in example code and handle opendir(3) error.

Modified:
  head/lib/libc/gen/directory.3

Modified: head/lib/libc/gen/directory.3
==============================================================================
--- head/lib/libc/gen/directory.3	Sat Mar 26 07:15:35 2011	(r220022)
+++ head/lib/libc/gen/directory.3	Sat Mar 26 07:15:57 2011	(r220023)
@@ -209,13 +209,16 @@ Sample code which searches a directory f
 .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 ,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201103260715.p2Q7FvDg006872>