From owner-svn-src-all@FreeBSD.ORG Sat Mar 26 07:15:57 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 75F941065674; Sat, 26 Mar 2011 07:15:57 +0000 (UTC) (envelope-from pjd@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6741A8FC17; Sat, 26 Mar 2011 07:15:57 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p2Q7Fv9L006874; Sat, 26 Mar 2011 07:15:57 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p2Q7FvDg006872; Sat, 26 Mar 2011 07:15:57 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201103260715.p2Q7FvDg006872@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Sat, 26 Mar 2011 07:15:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r220023 - head/lib/libc/gen X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 Mar 2011 07:15:57 -0000 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 ,