From owner-svn-src-all@FreeBSD.ORG Sun Jan 31 14:51:05 2010 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 3B67E1065672; Sun, 31 Jan 2010 14:51:05 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 29C918FC14; Sun, 31 Jan 2010 14:51:05 +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 o0VEp50B055102; Sun, 31 Jan 2010 14:51:05 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0VEp50a055100; Sun, 31 Jan 2010 14:51:05 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201001311451.o0VEp50a055100@svn.freebsd.org> From: Ed Schouten Date: Sun, 31 Jan 2010 14:51:05 +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: r203290 - 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: Sun, 31 Jan 2010 14:51:05 -0000 Author: ed Date: Sun Jan 31 14:51:04 2010 New Revision: 203290 URL: http://svn.freebsd.org/changeset/base/203290 Log: Perform some cleanups to devname(3). - Make sure the mode argument is either a character or a block device. - Use S_IS*() instead of checking S_IF*-flags by hand. - Don't use kern.devname when the argument is already NODEV. - Always call snprintf with the proper amount of arguments corresponding with the format. - Perform some whitespace fixes. Tabs instead of 4 spaces, missing space for return statement. - Remove unneeded includes. Modified: head/lib/libc/gen/devname.c Modified: head/lib/libc/gen/devname.c ============================================================================== --- head/lib/libc/gen/devname.c Sun Jan 31 14:35:49 2010 (r203289) +++ head/lib/libc/gen/devname.c Sun Jan 31 14:51:04 2010 (r203290) @@ -36,10 +36,7 @@ __FBSDID("$FreeBSD$"); #include #include -#include -#include #include -#include #include #include #include @@ -49,22 +46,22 @@ devname_r(dev_t dev, mode_t type, char * { int i; size_t j; - char *r; - if ((type & S_IFMT) == S_IFCHR) { + if (dev == NODEV || !(S_ISCHR(type) || S_ISBLK(dev))) { + strlcpy(buf, "#NODEV", len); + return (buf); + } + + if (S_ISCHR(type)) { j = len; i = sysctlbyname("kern.devname", buf, &j, &dev, sizeof (dev)); if (i == 0) - return (buf); + return (buf); } /* Finally just format it */ - if (dev == NODEV) - r = "#NODEV"; - else - r = "#%c:%d:0x%x"; - snprintf(buf, len, r, - (type & S_IFMT) == S_IFCHR ? 'C' : 'B', major(dev), minor(dev)); + snprintf(buf, len, "#%c:%d:0x%x", + S_ISCHR(type) ? 'C' : 'B', major(dev), minor(dev)); return (buf); } @@ -73,5 +70,5 @@ devname(dev_t dev, mode_t type) { static char buf[SPECNAMELEN + 1]; - return(devname_r(dev, type, buf, sizeof(buf))); + return (devname_r(dev, type, buf, sizeof(buf))); }