summaryrefslogtreecommitdiffstats
path: root/freebsd/sys/kern/subr_sbuf.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2019-07-09 11:14:53 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2019-07-09 14:45:47 +0200
commit5283630d2c9d40deb0183696d278e02644fe4326 (patch)
treed5695aea058ed05d4d9a4b84b5cb9986aaefd23f /freebsd/sys/kern/subr_sbuf.c
parentEPOCH(9): Add epoch_drain_callbacks() (diff)
downloadrtems-libbsd-5283630d2c9d40deb0183696d278e02644fe4326.tar.bz2
Update to FreeBSD stable/12 2019-07-09
Git mirror commit 3427c3416aa3c0f25124070959cca78024b94d85.
Diffstat (limited to 'freebsd/sys/kern/subr_sbuf.c')
-rw-r--r--freebsd/sys/kern/subr_sbuf.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/freebsd/sys/kern/subr_sbuf.c b/freebsd/sys/kern/subr_sbuf.c
index b51ed52c..c9696ab7 100644
--- a/freebsd/sys/kern/subr_sbuf.c
+++ b/freebsd/sys/kern/subr_sbuf.c
@@ -344,6 +344,21 @@ sbuf_setpos(struct sbuf *s, ssize_t pos)
}
/*
+ * Drain into a counter. Counts amount of data without producing output.
+ * Useful for cases like sysctl, where user may first request only size.
+ * This allows to avoid pointless allocation/freeing of large buffers.
+ */
+int
+sbuf_count_drain(void *arg, const char *data __unused, int len)
+{
+ size_t *sizep;
+
+ sizep = (size_t *)arg;
+ *sizep += len;
+ return (len);
+}
+
+/*
* Set up a drain function and argument on an sbuf to flush data to
* when the sbuf buffer overflows.
*/