summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2003-03-30 20:52:44 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2003-03-30 20:52:44 +0000
commit6a6d2e905f5d3da7fdea6b32e2f69ca78ee53de4 (patch)
tree2f0ad52ba5ba3f04a9243662ec3af40afbca1c78 /sys
parent35efc507db361c8615ae28b310e1232e1c429f26 (diff)
Use snprintf() to simplify device name construction, removing now
superfluous variables and the function 'number()'. ok deraadt@ and millert@
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/subr_autoconf.c34
1 files changed, 6 insertions, 28 deletions
diff --git a/sys/kern/subr_autoconf.c b/sys/kern/subr_autoconf.c
index 7464ec9a111..e23ca0b78f4 100644
--- a/sys/kern/subr_autoconf.c
+++ b/sys/kern/subr_autoconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_autoconf.c,v 1.32 2002/10/06 23:12:31 art Exp $ */
+/* $OpenBSD: subr_autoconf.c,v 1.33 2003/03/30 20:52:43 krw Exp $ */
/* $NetBSD: subr_autoconf.c,v 1.21 1996/04/04 06:06:18 cgd Exp $ */
/*
@@ -87,7 +87,6 @@ static struct cftable staticcftable = {
#endif /* AUTOCONF_VERBOSE */
int autoconf_verbose = AUTOCONF_VERBOSE; /* trace probe calls */
-static char *number(char *, int);
static void mapply(struct matchinfo *, struct cfdata *);
struct deferred_config {
@@ -339,22 +338,6 @@ config_rootfound(rootname, aux)
return (NULL);
}
-/* just like sprintf(buf, "%d") except that it works from the end */
-char *
-number(ep, n)
- register char *ep;
- register int n;
-{
-
- *--ep = 0;
- while (n >= 10) {
- *--ep = (n % 10) + '0';
- n /= 10;
- }
- *--ep = n + '0';
- return (ep);
-}
-
/*
* Attach a found device. Allocates memory for device variables.
*/
@@ -436,9 +419,7 @@ config_make_softc(parent, cf)
register struct device *dev;
register struct cfdriver *cd;
register struct cfattach *ca;
- register size_t lname, lunit;
- register char *xunit;
- char num[10];
+ register size_t lname;
cd = cf->cf_driver;
ca = cf->cf_attach;
@@ -465,14 +446,11 @@ config_make_softc(parent, cf)
dev->dv_unit = cf->cf_unit;
/* compute length of name and decimal expansion of unit number */
- lname = strlen(cd->cd_name);
- xunit = number(&num[sizeof num], dev->dv_unit);
- lunit = &num[sizeof num] - xunit;
- if (lname + lunit >= sizeof(dev->dv_xname))
- panic("config_make_softc: device name too long");
- bcopy(cd->cd_name, dev->dv_xname, lname);
- bcopy(xunit, dev->dv_xname + lname, lunit);
+ lname = snprintf(dev->dv_xname, sizeof(dev->dv_xname), "%s%d",
+ cd->cd_name, dev->dv_unit);
+ if (lname >= sizeof(dev->dv_xname))
+ panic("config_make_softc: device name too long");
dev->dv_parent = parent;
/* put this device in the devices array */