kern/90602: [PATCH] New function: sbuf_size(), which returns size of sbuf

Wojciech A. Koszek dunstan at freebsd.czest.pl
Sun Dec 18 05:50:04 PST 2005


>Number:         90602
>Category:       kern
>Synopsis:       [PATCH] New function: sbuf_size(), which returns size of sbuf
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Dec 18 13:50:02 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     Wojciech A. Koszek
>Release:        FreeBSD 7.0-CURRENT i386
>Organization:
>Environment:
System: FreeBSD laptop.freebsd.czest.pl 7.0-CURRENT FreeBSD 7.0-CURRENT #2: Sun Dec 18 01:31:49 CET 2005 dunstan at laptop.freebsd.czest.pl:/usr/obj/usr/src/sys/LAPTOP i386


>Description:
It's hard to determine buffer size allocated for sbuf. I'd find it
really useful and will be happy to see it commited.
>How-To-Repeat:

>Fix:
I have implemented sbuf_size() to fill this gap and updated manual page
(with minor style(9) tweak):

	http://freebsd.czest.pl/dunstan/FreeBSD/sbuf_size.0.patch

Comments are welcome!

--- sbuf_size.0.patch begins here ---
(c) 2005 <Wojciech A. Koszek dunstan^freebsd.czest.pl>

Patch against FreeBSD 7.0-CURRENT, kern.osreldate: 700008.

diff -upr /usr/src/share/man/man9/sbuf.9 src/share/man/man9/sbuf.9
--- /usr/src/share/man/man9/sbuf.9	Fri Jul  9 13:44:49 2004
+++ src/share/man/man9/sbuf.9	Sun Dec 18 14:12:41 2005
@@ -46,6 +46,7 @@
 .Nm sbuf_finish ,
 .Nm sbuf_data ,
 .Nm sbuf_len ,
+.Nm sbuf_size ,
 .Nm sbuf_done ,
 .Nm sbuf_delete
 .Nd safe string formatting
@@ -87,6 +88,8 @@
 .Ft int
 .Fn sbuf_len "struct sbuf *s"
 .Ft int
+.Fn sbuf_size "struct sbuf *s"
+.Ft int
 .Fn sbuf_done "struct sbuf *s"
 .Ft void
 .Fn sbuf_delete "struct sbuf *s"
@@ -291,6 +294,9 @@ functions return the actual string and i
 .Fn sbuf_data
 only works on a finished
 .Fa sbuf .
+.Fn sbuf_size
+returns size of data buffer allocated for
+.Fa sbuf .
 .Fn sbuf_done
 returns non-zero if the sbuf is finished.
 .Sh NOTES
@@ -337,6 +343,9 @@ and
 return
 .Dv NULL
 and \-1, respectively, if the buffer overflowed.
+.Pp
+.Fn sbuf_size
+returns size of allocated buffer.
 .Sh SEE ALSO
 .Xr printf 3 ,
 .Xr strcat 3 ,
diff -upr /usr/src/sys/kern/subr_sbuf.c src/sys/kern/subr_sbuf.c
--- /usr/src/sys/kern/subr_sbuf.c	Thu Feb 10 13:02:37 2005
+++ src/sys/kern/subr_sbuf.c	Sun Dec 18 14:14:57 2005
@@ -547,6 +547,18 @@ sbuf_len(struct sbuf *s)
 }
 
 /*
+ * Return the size of data buffer.
+ */
+int
+sbuf_size(struct sbuf *s)
+{
+	assert_sbuf_integrity(s);
+
+	return s->s_size;
+}
+
+
+/*
  * Clear an sbuf, free its buffer if necessary.
  */
 void
@@ -572,5 +584,5 @@ int
 sbuf_done(struct sbuf *s)
 {
 
-	return(SBUF_ISFINISHED(s));
+	return (SBUF_ISFINISHED(s));
 }
diff -upr /usr/src/sys/sys/sbuf.h src/sys/sys/sbuf.h
--- /usr/src/sys/sys/sbuf.h	Fri Jul  9 13:35:30 2004
+++ src/sys/sys/sbuf.h	Sat Dec 17 00:50:40 2005
@@ -70,6 +70,7 @@ int		 sbuf_overflowed(struct sbuf *);
 void		 sbuf_finish(struct sbuf *);
 char		*sbuf_data(struct sbuf *);
 int		 sbuf_len(struct sbuf *);
+int		 sbuf_size(struct sbuf *);
 int		 sbuf_done(struct sbuf *);
 void		 sbuf_delete(struct sbuf *);
 
--- sbuf_size.0.patch ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list