summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1999-07-18 10:19:48 +0000
committerphk <phk@FreeBSD.org>1999-07-18 10:19:48 +0000
commitc037f8cfd9d86eb1b1aab8c1080f6277d0fc3fb7 (patch)
tree25b0867f70c5637bad6ea82b928e6500fa8f1282 /lib
parentd51b32f103a73f7cbbbb134928dcbae4cba0509d (diff)
downloadFreeBSD-src-c037f8cfd9d86eb1b1aab8c1080f6277d0fc3fb7.zip
FreeBSD-src-c037f8cfd9d86eb1b1aab8c1080f6277d0fc3fb7.tar.gz
Make devname(3) return something more intelligent than NULL if it doesn't
find anything in the database.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/devname.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/libc/gen/devname.c b/lib/libc/gen/devname.c
index 39178fe..898c8e8 100644
--- a/lib/libc/gen/devname.c
+++ b/lib/libc/gen/devname.c
@@ -44,9 +44,10 @@ static char sccsid[] = "@(#)devname.c 8.2 (Berkeley) 4/29/95";
#include <paths.h>
#include <stdio.h>
#include <string.h>
+#include <sys/stat.h>
-char *
-devname(dev, type)
+static char *
+xdevname(dev, type)
dev_t dev;
mode_t type;
{
@@ -78,3 +79,27 @@ devname(dev, type)
key.size = sizeof(bkey);
return ((db->get)(db, &key, &data, 0) ? NULL : (char *)data.data);
}
+
+char *
+devname(dev, type)
+ dev_t dev;
+ mode_t type;
+{
+ static char buf[20];
+ char *r;
+
+ r = xdevname(dev, type);
+ if (!r) {
+ r = buf;
+ if (minor(dev) > 255) {
+ sprintf(buf, "#%c%d:0x%x",
+ (type & S_IFMT) == S_IFCHR ? 'C' : 'B',
+ major(dev), minor(dev));
+ } else {
+ sprintf(buf, "#%c%d:%d",
+ (type & S_IFMT) == S_IFCHR ? 'C' : 'B',
+ major(dev), minor(dev));
+ }
+ }
+ return (r);
+}
OpenPOWER on IntegriCloud