From c2c1c946ae25855c779b03f9b612cfa2750a94aa Mon Sep 17 00:00:00 2001 From: des Date: Sat, 9 Aug 2008 11:14:05 +0000 Subject: [PATCH] Add sbuf_new_auto as a shortcut for the very common case of creating a completely dynamic sbuf. Obtained from: Varnish MFC after: 2 weeks --- lib/libgeom/geom_xml2tree.c | 2 +- sbin/ifconfig/regdomain.c | 2 +- sys/dev/acpi_support/acpi_asus.c | 2 +- sys/dev/led/led.c | 2 +- sys/geom/concat/g_concat.c | 2 +- sys/geom/geom_ccd.c | 4 ++-- sys/geom/geom_ctl.c | 2 +- sys/geom/geom_disk.c | 2 +- sys/geom/geom_kern.c | 6 +++--- sys/geom/geom_slice.c | 2 +- sys/geom/geom_subr.c | 4 ++-- sys/geom/part/g_part.c | 14 +++++++------- sys/geom/stripe/g_stripe.c | 2 +- sys/kern/vfs_mount.c | 2 +- sys/security/mac_portacl/mac_portacl.c | 2 +- sys/sys/sbuf.h | 2 ++ tools/regression/geom/ConfCmp/ConfCmp.c | 4 ++-- tools/regression/geom/MdLoad/MdLoad.c | 2 +- 18 files changed, 30 insertions(+), 28 deletions(-) diff --git a/lib/libgeom/geom_xml2tree.c b/lib/libgeom/geom_xml2tree.c index 08fb394eefc4..1c7e22b56895 100644 --- a/lib/libgeom/geom_xml2tree.c +++ b/lib/libgeom/geom_xml2tree.c @@ -68,7 +68,7 @@ StartElement(void *userData, const char *name, const char **attr) mt = userData; mt->level++; - mt->sbuf[mt->level] = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + mt->sbuf[mt->level] = sbuf_new_auto(); id = NULL; ref = NULL; for (i = 0; attr[i] != NULL; i += 2) { diff --git a/sbin/ifconfig/regdomain.c b/sbin/ifconfig/regdomain.c index 095650709daf..c9a7921f6473 100644 --- a/sbin/ifconfig/regdomain.c +++ b/sbin/ifconfig/regdomain.c @@ -78,7 +78,7 @@ start_element(void *data, const char *name, const char **attr) /* XXX force parser to abort */ return; } - mt->sbuf[mt->level] = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + mt->sbuf[mt->level] = sbuf_new_auto(); id = ref = mode = NULL; for (i = 0; attr[i] != NULL; i += 2) { if (iseq(attr[i], "id")) { diff --git a/sys/dev/acpi_support/acpi_asus.c b/sys/dev/acpi_support/acpi_asus.c index 3730fe8986a6..f6b33f439a02 100644 --- a/sys/dev/acpi_support/acpi_asus.c +++ b/sys/dev/acpi_support/acpi_asus.c @@ -565,7 +565,7 @@ acpi_asus_probe(device_t dev) } } - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); if (sb == NULL) return (ENOMEM); diff --git a/sys/dev/led/led.c b/sys/dev/led/led.c index 73af18a6c758..d086f4e5e38e 100644 --- a/sys/dev/led/led.c +++ b/sys/dev/led/led.c @@ -142,7 +142,7 @@ led_write(struct cdev *dev, struct uio *uio, int ioflag) return(error); } - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); if (sb == NULL) { free(s2, M_DEVBUF); return (ENOMEM); diff --git a/sys/geom/concat/g_concat.c b/sys/geom/concat/g_concat.c index 9dae373bffd7..ad56f43490f8 100644 --- a/sys/geom/concat/g_concat.c +++ b/sys/geom/concat/g_concat.c @@ -748,7 +748,7 @@ g_concat_ctl_create(struct gctl_req *req, struct g_class *mp) } sc = gp->softc; - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); sbuf_printf(sb, "Can't attach disk(s) to %s:", gp->name); for (attached = 0, no = 1; no < *nargs; no++) { snprintf(param, sizeof(param), "arg%u", no); diff --git a/sys/geom/geom_ccd.c b/sys/geom/geom_ccd.c index e31f23a48ae5..75d7f0f25d24 100644 --- a/sys/geom/geom_ccd.c +++ b/sys/geom/geom_ccd.c @@ -790,7 +790,7 @@ g_ccd_create(struct gctl_req *req, struct g_class *mp) pp->sectorsize = sc->sc_secsize; g_error_provider(pp, 0); - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); sbuf_printf(sb, "ccd%d: %d components ", sc->sc_unit, *nprovider); for (i = 0; i < *nprovider; i++) { sbuf_printf(sb, "%s%s", @@ -840,7 +840,7 @@ g_ccd_list(struct gctl_req *req, struct g_class *mp) up = gctl_get_paraml(req, "unit", sizeof (int)); unit = *up; - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); LIST_FOREACH(gp, &mp->geom, geom) { cs = gp->softc; if (cs == NULL || (unit >= 0 && unit != cs->sc_unit)) diff --git a/sys/geom/geom_ctl.c b/sys/geom/geom_ctl.c index 25b9449bb008..55f34730031d 100644 --- a/sys/geom/geom_ctl.c +++ b/sys/geom/geom_ctl.c @@ -464,7 +464,7 @@ g_ctl_ioctl_ctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct th req = (void *)data; req->nerror = 0; - req->serror = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + req->serror = sbuf_new_auto(); /* It is an error if we cannot return an error text */ if (req->lerror < 2) return (EINVAL); diff --git a/sys/geom/geom_disk.c b/sys/geom/geom_disk.c index c39c03894ccd..20998bdd4175 100644 --- a/sys/geom/geom_disk.c +++ b/sys/geom/geom_disk.c @@ -517,7 +517,7 @@ sysctl_disks(SYSCTL_HANDLER_ARGS) int error; struct sbuf *sb; - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); g_waitfor_event(g_kern_disks, sb, M_WAITOK, NULL); error = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb) + 1); sbuf_delete(sb); diff --git a/sys/geom/geom_kern.c b/sys/geom/geom_kern.c index d32757928284..fc4e245f2fa8 100644 --- a/sys/geom/geom_kern.c +++ b/sys/geom/geom_kern.c @@ -180,7 +180,7 @@ sysctl_kern_geom_conftxt(SYSCTL_HANDLER_ARGS) int error; struct sbuf *sb; - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); g_waitfor_event(g_conftxt, sb, M_WAITOK, NULL); error = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb) + 1); sbuf_delete(sb); @@ -193,7 +193,7 @@ sysctl_kern_geom_confdot(SYSCTL_HANDLER_ARGS) int error; struct sbuf *sb; - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); g_waitfor_event(g_confdot, sb, M_WAITOK, NULL); error = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb) + 1); sbuf_delete(sb); @@ -206,7 +206,7 @@ sysctl_kern_geom_confxml(SYSCTL_HANDLER_ARGS) int error; struct sbuf *sb; - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); g_waitfor_event(g_confxml, sb, M_WAITOK, NULL); error = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb) + 1); sbuf_delete(sb); diff --git a/sys/geom/geom_slice.c b/sys/geom/geom_slice.c index 9462fdc06035..0bdb10c8222f 100644 --- a/sys/geom/geom_slice.c +++ b/sys/geom/geom_slice.c @@ -385,7 +385,7 @@ g_slice_config(struct g_geom *gp, u_int idx, int how, off_t offset, off_t length pp->mediasize = gsl->length; return (0); } - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); va_start(ap, fmt); sbuf_vprintf(sb, fmt, ap); va_end(ap); diff --git a/sys/geom/geom_subr.c b/sys/geom/geom_subr.c index 712ee50f42c7..b828ebc51cf4 100644 --- a/sys/geom/geom_subr.c +++ b/sys/geom/geom_subr.c @@ -324,7 +324,7 @@ g_new_geomf(struct g_class *mp, const char *fmt, ...) g_topology_assert(); G_VALID_CLASS(mp); - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); va_start(ap, fmt); sbuf_vprintf(sb, fmt, ap); va_end(ap); @@ -566,7 +566,7 @@ g_new_providerf(struct g_geom *gp, const char *fmt, ...) KASSERT(!(gp->flags & G_GEOM_WITHER), ("new provider on WITHERing geom(%s) (class %s)", gp->name, gp->class->name)); - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); va_start(ap, fmt); sbuf_vprintf(sb, fmt, ap); va_end(ap); diff --git a/sys/geom/part/g_part.c b/sys/geom/part/g_part.c index 4650b4ac25e6..e12c0fa03c93 100644 --- a/sys/geom/part/g_part.c +++ b/sys/geom/part/g_part.c @@ -506,7 +506,7 @@ g_part_ctl_add(struct gctl_req *req, struct g_part_parms *gpp) /* Provide feedback if so requested. */ if (gpp->gpp_parms & G_PART_PARM_OUTPUT) { - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); sbuf_printf(sb, "%s%s added\n", gp->name, G_PART_NAME(table, entry, buf, sizeof(buf))); sbuf_finish(sb); @@ -545,7 +545,7 @@ g_part_ctl_bootcode(struct gctl_req *req, struct g_part_parms *gpp) /* Provide feedback if so requested. */ if (gpp->gpp_parms & G_PART_PARM_OUTPUT) { - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); sbuf_printf(sb, "%s has bootcode\n", gp->name); sbuf_finish(sb); gctl_set_param(req, "output", sbuf_data(sb), sbuf_len(sb) + 1); @@ -749,7 +749,7 @@ g_part_ctl_create(struct gctl_req *req, struct g_part_parms *gpp) /* Provide feedback if so requested. */ if (gpp->gpp_parms & G_PART_PARM_OUTPUT) { - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); sbuf_printf(sb, "%s created\n", gp->name); sbuf_finish(sb); gctl_set_param(req, "output", sbuf_data(sb), sbuf_len(sb) + 1); @@ -821,7 +821,7 @@ g_part_ctl_delete(struct gctl_req *req, struct g_part_parms *gpp) /* Provide feedback if so requested. */ if (gpp->gpp_parms & G_PART_PARM_OUTPUT) { - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); sbuf_printf(sb, "%s%s deleted\n", gp->name, G_PART_NAME(table, entry, buf, sizeof(buf))); sbuf_finish(sb); @@ -877,7 +877,7 @@ g_part_ctl_destroy(struct gctl_req *req, struct g_part_parms *gpp) /* Provide feedback if so requested. */ if (gpp->gpp_parms & G_PART_PARM_OUTPUT) { - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); sbuf_printf(sb, "%s destroyed\n", gp->name); sbuf_finish(sb); gctl_set_param(req, "output", sbuf_data(sb), sbuf_len(sb) + 1); @@ -924,7 +924,7 @@ g_part_ctl_modify(struct gctl_req *req, struct g_part_parms *gpp) /* Provide feedback if so requested. */ if (gpp->gpp_parms & G_PART_PARM_OUTPUT) { - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); sbuf_printf(sb, "%s%s modified\n", gp->name, G_PART_NAME(table, entry, buf, sizeof(buf))); sbuf_finish(sb); @@ -991,7 +991,7 @@ g_part_ctl_setunset(struct gctl_req *req, struct g_part_parms *gpp, /* Provide feedback if so requested. */ if (gpp->gpp_parms & G_PART_PARM_OUTPUT) { - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); sbuf_printf(sb, "%s%s has %s %sset\n", gp->name, G_PART_NAME(table, entry, buf, sizeof(buf)), gpp->gpp_attrib, (set) ? "" : "un"); diff --git a/sys/geom/stripe/g_stripe.c b/sys/geom/stripe/g_stripe.c index c059df5e0645..88b0cad04833 100644 --- a/sys/geom/stripe/g_stripe.c +++ b/sys/geom/stripe/g_stripe.c @@ -1069,7 +1069,7 @@ g_stripe_ctl_create(struct gctl_req *req, struct g_class *mp) } sc = gp->softc; - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); sbuf_printf(sb, "Can't attach disk(s) to %s:", gp->name); for (attached = 0, no = 1; no < *nargs; no++) { snprintf(param, sizeof(param), "arg%u", no); diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index 744f4e9a1694..dc0cf8c564b1 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -2179,7 +2179,7 @@ mount_argf(struct mntarg *ma, const char *name, const char *fmt, ...) ma->v[ma->len].iov_len = strlen(name) + 1; ma->len++; - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); va_start(ap, fmt); sbuf_vprintf(sb, fmt, ap); va_end(ap); diff --git a/sys/security/mac_portacl/mac_portacl.c b/sys/security/mac_portacl/mac_portacl.c index 7afc63b85c34..aceda6908b14 100644 --- a/sys/security/mac_portacl/mac_portacl.c +++ b/sys/security/mac_portacl/mac_portacl.c @@ -310,7 +310,7 @@ rules_to_string(void) int needcomma; char *temp; - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sb = sbuf_new_auto(); needcomma = 0; mtx_lock(&rule_mtx); for (rule = TAILQ_FIRST(&rule_head); rule != NULL; diff --git a/sys/sys/sbuf.h b/sys/sys/sbuf.h index 0364c5179e27..fce24beeed13 100644 --- a/sys/sys/sbuf.h +++ b/sys/sys/sbuf.h @@ -56,6 +56,8 @@ __BEGIN_DECLS * API functions */ struct sbuf *sbuf_new(struct sbuf *, char *, int, int); +#define sbuf_new_auto() \ + sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND) void sbuf_clear(struct sbuf *); int sbuf_setpos(struct sbuf *, int); int sbuf_bcat(struct sbuf *, const void *, size_t); diff --git a/tools/regression/geom/ConfCmp/ConfCmp.c b/tools/regression/geom/ConfCmp/ConfCmp.c index 1ddf502f9110..8c551cf8e846 100644 --- a/tools/regression/geom/ConfCmp/ConfCmp.c +++ b/tools/regression/geom/ConfCmp/ConfCmp.c @@ -82,9 +82,9 @@ new_node(void) struct node *np; np = calloc(1, sizeof *np); - np->cont = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + np->cont = sbuf_new_auto(); sbuf_clear(np->cont); - np->key = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + np->key = sbuf_new_auto(); sbuf_clear(np->key); LIST_INIT(&np->children); return (np); diff --git a/tools/regression/geom/MdLoad/MdLoad.c b/tools/regression/geom/MdLoad/MdLoad.c index 710d7d385ed5..33ee4de3876e 100644 --- a/tools/regression/geom/MdLoad/MdLoad.c +++ b/tools/regression/geom/MdLoad/MdLoad.c @@ -208,7 +208,7 @@ g_simdisk_xml_load(const char *file) int fd, i; sc = calloc(1, sizeof *sc); - sc->sbuf = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + sc->sbuf = sbuf_new_auto(); LIST_INIT(&sc->sectors); XML_SetUserData(parser, sc); XML_SetElementHandler(parser, startElement, endElement);