aboutsummaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorEd Schouten <ed@FreeBSD.org>2010-01-31 14:51:04 +0000
committerEd Schouten <ed@FreeBSD.org>2010-01-31 14:51:04 +0000
commit49e5c8f314d7a068ad45d0602ec62cf666b30dc8 (patch)
tree64e48d4e4e23ffdcb956c8f7e2e4959c00556549 /lib/libc
parentb3e7ca23e791a41658f433cf02303024db6de91c (diff)
downloadsrc-49e5c8f314d7a068ad45d0602ec62cf666b30dc8.tar.gz
src-49e5c8f314d7a068ad45d0602ec62cf666b30dc8.zip
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.
Notes
Notes: svn path=/head/; revision=203290
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/gen/devname.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/lib/libc/gen/devname.c b/lib/libc/gen/devname.c
index 21e46e6b0e04..65a690fcdcc3 100644
--- a/lib/libc/gen/devname.c
+++ b/lib/libc/gen/devname.c
@@ -36,10 +36,7 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/sysctl.h>
-#include <err.h>
-#include <fcntl.h>
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#include <sys/stat.h>
@@ -49,22 +46,22 @@ devname_r(dev_t dev, mode_t type, char *buf, int len)
{
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)));
}