1863edaecSDag-Erling Smørgrav.\"- 272fba9d7SChristian Brueffer.\" Copyright (c) 2000 Poul-Henning Kamp and Dag-Erling Co�dan Sm�rgrav 3863edaecSDag-Erling Smørgrav.\" All rights reserved. 4863edaecSDag-Erling Smørgrav.\" 5863edaecSDag-Erling Smørgrav.\" Redistribution and use in source and binary forms, with or without 6863edaecSDag-Erling Smørgrav.\" modification, are permitted provided that the following conditions 7863edaecSDag-Erling Smørgrav.\" are met: 8863edaecSDag-Erling Smørgrav.\" 1. Redistributions of source code must retain the above copyright 9863edaecSDag-Erling Smørgrav.\" notice, this list of conditions and the following disclaimer. 10863edaecSDag-Erling Smørgrav.\" 2. Redistributions in binary form must reproduce the above copyright 11863edaecSDag-Erling Smørgrav.\" notice, this list of conditions and the following disclaimer in the 12863edaecSDag-Erling Smørgrav.\" documentation and/or other materials provided with the distribution. 13863edaecSDag-Erling Smørgrav.\" 14863edaecSDag-Erling Smørgrav.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15863edaecSDag-Erling Smørgrav.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16863edaecSDag-Erling Smørgrav.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17863edaecSDag-Erling Smørgrav.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18863edaecSDag-Erling Smørgrav.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19863edaecSDag-Erling Smørgrav.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20863edaecSDag-Erling Smørgrav.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21863edaecSDag-Erling Smørgrav.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22863edaecSDag-Erling Smørgrav.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23863edaecSDag-Erling Smørgrav.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24863edaecSDag-Erling Smørgrav.\" SUCH DAMAGE. 25863edaecSDag-Erling Smørgrav.\" 26863edaecSDag-Erling Smørgrav.\" $FreeBSD$ 27863edaecSDag-Erling Smørgrav.\" 2872fba9d7SChristian Brueffer.Dd May 17, 2009 295f95f24bSRuslan Ermilov.Dt SBUF 9 303d45e180SRuslan Ermilov.Os 31863edaecSDag-Erling Smørgrav.Sh NAME 3281ae4b8dSRuslan Ermilov.Nm sbuf , 33863edaecSDag-Erling Smørgrav.Nm sbuf_new , 3472fba9d7SChristian Brueffer.Nm sbuf_new_auto , 35e499b74dSDag-Erling Smørgrav.Nm sbuf_clear , 36863edaecSDag-Erling Smørgrav.Nm sbuf_setpos , 37b0def2b5SDag-Erling Smørgrav.Nm sbuf_bcat , 38b0def2b5SDag-Erling Smørgrav.Nm sbuf_bcopyin , 39b0def2b5SDag-Erling Smørgrav.Nm sbuf_bcpy , 40863edaecSDag-Erling Smørgrav.Nm sbuf_cat , 41b0def2b5SDag-Erling Smørgrav.Nm sbuf_copyin , 42863edaecSDag-Erling Smørgrav.Nm sbuf_cpy , 43863edaecSDag-Erling Smørgrav.Nm sbuf_printf , 44371c0c84SKelly Yancey.Nm sbuf_vprintf , 45863edaecSDag-Erling Smørgrav.Nm sbuf_putc , 46371c0c84SKelly Yancey.Nm sbuf_trim , 47e499b74dSDag-Erling Smørgrav.Nm sbuf_overflowed , 48863edaecSDag-Erling Smørgrav.Nm sbuf_finish , 49863edaecSDag-Erling Smørgrav.Nm sbuf_data , 50863edaecSDag-Erling Smørgrav.Nm sbuf_len , 51c5f9218bSPoul-Henning Kamp.Nm sbuf_done , 52863edaecSDag-Erling Smørgrav.Nm sbuf_delete 53863edaecSDag-Erling Smørgrav.Nd safe string formatting 54863edaecSDag-Erling Smørgrav.Sh SYNOPSIS 5532eef9aeSRuslan Ermilov.In sys/types.h 5632eef9aeSRuslan Ermilov.In sys/sbuf.h 578a5bc771SBruce Evans.Ft struct sbuf * 58e499b74dSDag-Erling Smørgrav.Fn sbuf_new "struct sbuf *s" "char *buf" "int length" "int flags" 5972fba9d7SChristian Brueffer.Ft struct sbuf * 6072fba9d7SChristian Brueffer.Fn sbuf_new_auto 61e499b74dSDag-Erling Smørgrav.Ft void 62e499b74dSDag-Erling Smørgrav.Fn sbuf_clear "struct sbuf *s" 63863edaecSDag-Erling Smørgrav.Ft int 64e499b74dSDag-Erling Smørgrav.Fn sbuf_setpos "struct sbuf *s" "int pos" 65863edaecSDag-Erling Smørgrav.Ft int 664aa90de3SDag-Erling Smørgrav.Fn sbuf_bcat "struct sbuf *s" "const void *buf" "size_t len" 67b0def2b5SDag-Erling Smørgrav.Ft int 68b0def2b5SDag-Erling Smørgrav.Fn sbuf_bcopyin "struct sbuf *s" "const void *uaddr" "size_t len" 69b0def2b5SDag-Erling Smørgrav.Ft int 704aa90de3SDag-Erling Smørgrav.Fn sbuf_bcpy "struct sbuf *s" "const void *buf" "size_t len" 71b0def2b5SDag-Erling Smørgrav.Ft int 723393f8daSKenneth D. Merry.Fn sbuf_cat "struct sbuf *s" "const char *str" 73863edaecSDag-Erling Smørgrav.Ft int 74b0def2b5SDag-Erling Smørgrav.Fn sbuf_copyin "struct sbuf *s" "const void *uaddr" "size_t len" 75b0def2b5SDag-Erling Smørgrav.Ft int 763393f8daSKenneth D. Merry.Fn sbuf_cpy "struct sbuf *s" "const char *str" 77863edaecSDag-Erling Smørgrav.Ft int 788cce2ebaSDag-Erling Smørgrav.Fn sbuf_printf "struct sbuf *s" "const char *fmt" "..." 79863edaecSDag-Erling Smørgrav.Ft int 80371c0c84SKelly Yancey.Fn sbuf_vprintf "struct sbuf *s" "const char *fmt" "va_list ap" 81371c0c84SKelly Yancey.Ft int 82863edaecSDag-Erling Smørgrav.Fn sbuf_putc "struct sbuf *s" "int c" 83863edaecSDag-Erling Smørgrav.Ft int 84371c0c84SKelly Yancey.Fn sbuf_trim "struct sbuf *s" 85371c0c84SKelly Yancey.Ft int 86e499b74dSDag-Erling Smørgrav.Fn sbuf_overflowed "struct sbuf *s" 87e499b74dSDag-Erling Smørgrav.Ft void 88863edaecSDag-Erling Smørgrav.Fn sbuf_finish "struct sbuf *s" 89863edaecSDag-Erling Smørgrav.Ft char * 90863edaecSDag-Erling Smørgrav.Fn sbuf_data "struct sbuf *s" 91e499b74dSDag-Erling Smørgrav.Ft int 92863edaecSDag-Erling Smørgrav.Fn sbuf_len "struct sbuf *s" 93c5f9218bSPoul-Henning Kamp.Ft int 94c5f9218bSPoul-Henning Kamp.Fn sbuf_done "struct sbuf *s" 95863edaecSDag-Erling Smørgrav.Ft void 96863edaecSDag-Erling Smørgrav.Fn sbuf_delete "struct sbuf *s" 97863edaecSDag-Erling Smørgrav.Sh DESCRIPTION 98863edaecSDag-Erling SmørgravThe 9981ae4b8dSRuslan Ermilov.Nm 10067e35919SSheldon Hearnfamily of functions allows one to safely allocate, construct and 101*db960cf0SMatthew D Flemingrelease bounded NUL-terminated strings in kernel space. 102863edaecSDag-Erling SmørgravInstead of arrays of characters, these functions operate on structures 103863edaecSDag-Erling Smørgravcalled 104863edaecSDag-Erling Smørgrav.Fa sbufs , 105863edaecSDag-Erling Smørgravdefined in 106fe08efe6SRuslan Ermilov.In sys/sbuf.h . 107863edaecSDag-Erling Smørgrav.Pp 108863edaecSDag-Erling SmørgravThe 109863edaecSDag-Erling Smørgrav.Fn sbuf_new 110863edaecSDag-Erling Smørgravfunction initializes the 111863edaecSDag-Erling Smørgrav.Fa sbuf 112863edaecSDag-Erling Smørgravpointed to by its first argument. 113d6479358SDag-Erling SmørgravIf that pointer is 114d6479358SDag-Erling Smørgrav.Dv NULL , 115d6479358SDag-Erling Smørgrav.Fn sbuf_new 116d6479358SDag-Erling Smørgravallocates a 117d68b700aSRuslan Ermilov.Vt struct sbuf 118d6479358SDag-Erling Smørgravusing 119d6479358SDag-Erling Smørgrav.Xr malloc 9 . 120863edaecSDag-Erling SmørgravThe 121863edaecSDag-Erling Smørgrav.Fa buf 122863edaecSDag-Erling Smørgravargument is a pointer to a buffer in which to store the actual string; 123863edaecSDag-Erling Smørgravif it is 124863edaecSDag-Erling Smørgrav.Dv NULL , 125863edaecSDag-Erling Smørgrav.Fn sbuf_new 126863edaecSDag-Erling Smørgravwill allocate one using 127863edaecSDag-Erling Smørgrav.Xr malloc 9 . 128863edaecSDag-Erling SmørgravThe 129863edaecSDag-Erling Smørgrav.Fa length 130371c0c84SKelly Yanceyis the initial size of the storage buffer. 131863edaecSDag-Erling SmørgravThe fourth argument, 132863edaecSDag-Erling Smørgrav.Fa flags , 133371c0c84SKelly Yanceymay be comprised of the following flags: 1343b0536faSRuslan Ermilov.Bl -tag -width ".Dv SBUF_AUTOEXTEND" 135371c0c84SKelly Yancey.It Dv SBUF_FIXEDLEN 1363b0536faSRuslan ErmilovThe storage buffer is fixed at its initial size. 137371c0c84SKelly YanceyAttempting to extend the sbuf beyond this size results in an overflow condition. 138371c0c84SKelly Yancey.It Dv SBUF_AUTOEXTEND 139371c0c84SKelly YanceyThis indicates that the storage buffer may be extended as necessary, so long 140371c0c84SKelly Yanceyas resources allow, to hold additional data. 141371c0c84SKelly Yancey.El 142863edaecSDag-Erling Smørgrav.Pp 143863edaecSDag-Erling SmørgravNote that if 144863edaecSDag-Erling Smørgrav.Fa buf 145863edaecSDag-Erling Smørgravis not 146863edaecSDag-Erling Smørgrav.Dv NULL , 147863edaecSDag-Erling Smørgravit must point to an array of at least 148863edaecSDag-Erling Smørgrav.Fa length 149863edaecSDag-Erling Smørgravcharacters. 15091c9d24eSDag-Erling SmørgravThe result of accessing that array directly while it is in use by the 15191c9d24eSDag-Erling Smørgravsbuf is undefined. 15291c9d24eSDag-Erling Smørgrav.Pp 15391c9d24eSDag-Erling SmørgravThe 15472fba9d7SChristian Brueffer.Fn sbuf_new_auto 15572fba9d7SChristian Bruefferfunction is a shortcut for creating a completely dynamic 15672fba9d7SChristian Brueffer.Nm . 15772fba9d7SChristian BruefferIt is the equivalent of calling 15872fba9d7SChristian Brueffer.Fn sbuf_new 15972fba9d7SChristian Bruefferwith values 16072fba9d7SChristian Brueffer.Dv NULL , 16172fba9d7SChristian Brueffer.Dv NULL , 16272fba9d7SChristian Brueffer.Dv 0 , 16372fba9d7SChristian Bruefferand 16472fba9d7SChristian Brueffer.Dv SBUF_AUTOEXTEND . 16572fba9d7SChristian Brueffer.Pp 16672fba9d7SChristian BruefferThe 16791c9d24eSDag-Erling Smørgrav.Fn sbuf_delete 16891c9d24eSDag-Erling Smørgravfunction clears the 16991c9d24eSDag-Erling Smørgrav.Fa sbuf 17091c9d24eSDag-Erling Smørgravand frees any memory allocated for it. 17191c9d24eSDag-Erling SmørgravThere must be a call to 17291c9d24eSDag-Erling Smørgrav.Fn sbuf_delete 17391c9d24eSDag-Erling Smørgravfor every call to 17491c9d24eSDag-Erling Smørgrav.Fn sbuf_new . 17591c9d24eSDag-Erling SmørgravAny attempt to access the sbuf after it has been deleted will fail. 176863edaecSDag-Erling Smørgrav.Pp 177863edaecSDag-Erling SmørgravThe 178e499b74dSDag-Erling Smørgrav.Fn sbuf_clear 179e499b74dSDag-Erling Smørgravfunction invalidates the contents of the 180e499b74dSDag-Erling Smørgrav.Fa sbuf 181e499b74dSDag-Erling Smørgravand resets its position to zero. 182e499b74dSDag-Erling Smørgrav.Pp 183e499b74dSDag-Erling SmørgravThe 184863edaecSDag-Erling Smørgrav.Fn sbuf_setpos 185863edaecSDag-Erling Smørgravfunction sets the 186863edaecSDag-Erling Smørgrav.Fa sbuf Ns 's 187371c0c84SKelly Yanceyend position to 188863edaecSDag-Erling Smørgrav.Fa pos , 189863edaecSDag-Erling Smørgravwhich is a value between zero and one less than the size of the 190863edaecSDag-Erling Smørgravstorage buffer. 191371c0c84SKelly YanceyThis effectively truncates the sbuf at the new position. 192863edaecSDag-Erling Smørgrav.Pp 193863edaecSDag-Erling SmørgravThe 194b0def2b5SDag-Erling Smørgrav.Fn sbuf_bcat 195b0def2b5SDag-Erling Smørgravfunction appends the first 196b0def2b5SDag-Erling Smørgrav.Fa len 1974aa90de3SDag-Erling Smørgravbytes from the buffer 1984aa90de3SDag-Erling Smørgrav.Fa buf 199b0def2b5SDag-Erling Smørgravto the 200b0def2b5SDag-Erling Smørgrav.Fa sbuf . 201b0def2b5SDag-Erling Smørgrav.Pp 202b0def2b5SDag-Erling SmørgravThe 203b0def2b5SDag-Erling Smørgrav.Fn sbuf_bcopyin 204b0def2b5SDag-Erling Smørgravfunction copies 205b0def2b5SDag-Erling Smørgrav.Fa len 206b0def2b5SDag-Erling Smørgravbytes from the specified userland address into the 207b0def2b5SDag-Erling Smørgrav.Fa sbuf . 208b0def2b5SDag-Erling Smørgrav.Pp 209b0def2b5SDag-Erling SmørgravThe 210b0def2b5SDag-Erling Smørgrav.Fn sbuf_bcpy 211b0def2b5SDag-Erling Smørgravfunction replaces the contents of the 212b0def2b5SDag-Erling Smørgrav.Fa sbuf 213b0def2b5SDag-Erling Smørgravwith the first 214b0def2b5SDag-Erling Smørgrav.Fa len 2154aa90de3SDag-Erling Smørgravbytes from the buffer 2164aa90de3SDag-Erling Smørgrav.Fa buf . 217b0def2b5SDag-Erling Smørgrav.Pp 218b0def2b5SDag-Erling SmørgravThe 219863edaecSDag-Erling Smørgrav.Fn sbuf_cat 220b0def2b5SDag-Erling Smørgravfunction appends the NUL-terminated string 221863edaecSDag-Erling Smørgrav.Fa str 222863edaecSDag-Erling Smørgravto the 223863edaecSDag-Erling Smørgrav.Fa sbuf 224863edaecSDag-Erling Smørgravat the current position. 225863edaecSDag-Erling Smørgrav.Pp 226863edaecSDag-Erling SmørgravThe 227b0def2b5SDag-Erling Smørgrav.Fn sbuf_copyin 228b0def2b5SDag-Erling Smørgravfunction copies a NUL-terminated string from the specified userland 229b0def2b5SDag-Erling Smørgravaddress into the 230b0def2b5SDag-Erling Smørgrav.Fa sbuf . 231b0def2b5SDag-Erling SmørgravIf the 232b0def2b5SDag-Erling Smørgrav.Fa len 233b0def2b5SDag-Erling Smørgravargument is non-zero, no more than 234b0def2b5SDag-Erling Smørgrav.Fa len 235b0def2b5SDag-Erling Smørgravcharacters (not counting the terminating NUL) are copied; otherwise 236b0def2b5SDag-Erling Smørgravthe entire string, or as much of it as can fit in the 237b0def2b5SDag-Erling Smørgrav.Fa sbuf , 238b0def2b5SDag-Erling Smørgravis copied. 239b0def2b5SDag-Erling Smørgrav.Pp 240b0def2b5SDag-Erling SmørgravThe 241863edaecSDag-Erling Smørgrav.Fn sbuf_cpy 242863edaecSDag-Erling Smørgravfunction replaces the contents of the 243863edaecSDag-Erling Smørgrav.Fa sbuf 244b0def2b5SDag-Erling Smørgravwith those of the NUL-terminated string 245863edaecSDag-Erling Smørgrav.Fa str . 246863edaecSDag-Erling SmørgravThis is equivalent to calling 247863edaecSDag-Erling Smørgrav.Fn sbuf_cat 248863edaecSDag-Erling Smørgravwith a fresh 249863edaecSDag-Erling Smørgrav.Fa sbuf 250863edaecSDag-Erling Smørgravor one which position has been reset to zero with 251e499b74dSDag-Erling Smørgrav.Fn sbuf_clear 252e499b74dSDag-Erling Smørgravor 253863edaecSDag-Erling Smørgrav.Fn sbuf_setpos . 254863edaecSDag-Erling Smørgrav.Pp 255863edaecSDag-Erling SmørgravThe 256863edaecSDag-Erling Smørgrav.Fn sbuf_printf 257863edaecSDag-Erling Smørgravfunction formats its arguments according to the format string pointed 258863edaecSDag-Erling Smørgravto by 259863edaecSDag-Erling Smørgrav.Fa fmt 260863edaecSDag-Erling Smørgravand appends the resulting string to the 261863edaecSDag-Erling Smørgrav.Fa sbuf 262863edaecSDag-Erling Smørgravat the current position. 263863edaecSDag-Erling Smørgrav.Pp 264863edaecSDag-Erling SmørgravThe 265371c0c84SKelly Yancey.Fn sbuf_vprintf 266371c0c84SKelly Yanceyfunction behaves the same as 267371c0c84SKelly Yancey.Fn sbuf_printf 268371c0c84SKelly Yanceyexcept that the arguments are obtained from the variable-length argument list 269371c0c84SKelly Yancey.Fa ap . 270371c0c84SKelly Yancey.Pp 271371c0c84SKelly YanceyThe 272863edaecSDag-Erling Smørgrav.Fn sbuf_putc 273863edaecSDag-Erling Smørgravfunction appends the character 274863edaecSDag-Erling Smørgrav.Fa c 275863edaecSDag-Erling Smørgravto the 276863edaecSDag-Erling Smørgrav.Fa sbuf 277863edaecSDag-Erling Smørgravat the current position. 278863edaecSDag-Erling Smørgrav.Pp 279863edaecSDag-Erling SmørgravThe 280371c0c84SKelly Yancey.Fn sbuf_trim 281371c0c84SKelly Yanceyfunction removes trailing whitespace from the 282371c0c84SKelly Yancey.Fa sbuf . 283371c0c84SKelly Yancey.Pp 284371c0c84SKelly YanceyThe 285e499b74dSDag-Erling Smørgrav.Fn sbuf_overflowed 286e499b74dSDag-Erling Smørgravfunction returns a non-zero value if the 287e499b74dSDag-Erling Smørgrav.Fa sbuf 288e499b74dSDag-Erling Smørgravoverflowed. 289e499b74dSDag-Erling Smørgrav.Pp 290e499b74dSDag-Erling SmørgravThe 291863edaecSDag-Erling Smørgrav.Fn sbuf_finish 292*db960cf0SMatthew D Flemingfunction NUL-terminates the 293863edaecSDag-Erling Smørgrav.Fa sbuf 294863edaecSDag-Erling Smørgravand marks it as finished, which means that it may no longer be 295863edaecSDag-Erling Smørgravmodified using 296863edaecSDag-Erling Smørgrav.Fn sbuf_setpos , 297863edaecSDag-Erling Smørgrav.Fn sbuf_cat , 2983393f8daSKenneth D. Merry.Fn sbuf_cpy , 299863edaecSDag-Erling Smørgrav.Fn sbuf_printf 300863edaecSDag-Erling Smørgravor 301*db960cf0SMatthew D Fleming.Fn sbuf_putc , 302*db960cf0SMatthew D Fleminguntil 303*db960cf0SMatthew D Fleming.Fn sbuf_clear 304*db960cf0SMatthew D Flemingis used to reset the sbuf. 305863edaecSDag-Erling Smørgrav.Pp 306863edaecSDag-Erling SmørgravThe 307863edaecSDag-Erling Smørgrav.Fn sbuf_data 308863edaecSDag-Erling Smørgravand 309863edaecSDag-Erling Smørgrav.Fn sbuf_len 310e499b74dSDag-Erling Smørgravfunctions return the actual string and its length, respectively; 311e499b74dSDag-Erling Smørgrav.Fn sbuf_data 312e499b74dSDag-Erling Smørgravonly works on a finished 313863edaecSDag-Erling Smørgrav.Fa sbuf . 314c5f9218bSPoul-Henning Kamp.Fn sbuf_done 315*db960cf0SMatthew D Flemingreturns non-zero if the 316*db960cf0SMatthew D Fleming.Fa sbuf 317*db960cf0SMatthew D Flemingis finished. 318863edaecSDag-Erling Smørgrav.Sh NOTES 319863edaecSDag-Erling SmørgravIf an operation caused an 320863edaecSDag-Erling Smørgrav.Fa sbuf 321e499b74dSDag-Erling Smørgravto overflow, most subsequent operations on it will fail until the 322e499b74dSDag-Erling Smørgrav.Fa sbuf 323e499b74dSDag-Erling Smørgravis finished using 324e499b74dSDag-Erling Smørgrav.Fn sbuf_finish 325e499b74dSDag-Erling Smørgravor reset using 326e499b74dSDag-Erling Smørgrav.Fn sbuf_clear , 327e499b74dSDag-Erling Smørgravor its position is reset to a value between 0 and one less than the 328e499b74dSDag-Erling Smørgravsize of its storage buffer using 329863edaecSDag-Erling Smørgrav.Fn sbuf_setpos , 330863edaecSDag-Erling Smørgravor it is reinitialized to a sufficiently short string using 331863edaecSDag-Erling Smørgrav.Fn sbuf_cpy . 332863edaecSDag-Erling Smørgrav.Sh RETURN VALUES 33381ae4b8dSRuslan ErmilovThe 334863edaecSDag-Erling Smørgrav.Fn sbuf_new 33581ae4b8dSRuslan Ermilovfunction returns 336d6479358SDag-Erling Smørgrav.Dv NULL 337d6479358SDag-Erling Smørgravif it failed to allocate a storage buffer, and a pointer to the new 338d6479358SDag-Erling Smørgrav.Fa sbuf 339863edaecSDag-Erling Smørgravotherwise. 340863edaecSDag-Erling Smørgrav.Pp 34181ae4b8dSRuslan ErmilovThe 342863edaecSDag-Erling Smørgrav.Fn sbuf_setpos 34381ae4b8dSRuslan Ermilovfunction returns \-1 if 344863edaecSDag-Erling Smørgrav.Fa pos 345863edaecSDag-Erling Smørgravwas invalid, and zero otherwise. 346863edaecSDag-Erling Smørgrav.Pp 34781ae4b8dSRuslan ErmilovThe 348863edaecSDag-Erling Smørgrav.Fn sbuf_cat , 349863edaecSDag-Erling Smørgrav.Fn sbuf_cpy , 350863edaecSDag-Erling Smørgrav.Fn sbuf_printf , 351371c0c84SKelly Yancey.Fn sbuf_putc , 352863edaecSDag-Erling Smørgravand 353371c0c84SKelly Yancey.Fn sbuf_trim 35481ae4b8dSRuslan Ermilovfunctions 355863edaecSDag-Erling Smørgravall return \-1 if the buffer overflowed, and zero otherwise. 356863edaecSDag-Erling Smørgrav.Pp 35781ae4b8dSRuslan ErmilovThe 358e499b74dSDag-Erling Smørgrav.Fn sbuf_overflowed 35981ae4b8dSRuslan Ermilovfunction 360e499b74dSDag-Erling Smørgravreturns a non-zero value if the buffer overflowed, and zero otherwise. 361e499b74dSDag-Erling Smørgrav.Pp 36281ae4b8dSRuslan ErmilovThe 363863edaecSDag-Erling Smørgrav.Fn sbuf_data 364863edaecSDag-Erling Smørgravand 365863edaecSDag-Erling Smørgrav.Fn sbuf_len 36681ae4b8dSRuslan Ermilovfunctions return 367863edaecSDag-Erling Smørgrav.Dv NULL 368e499b74dSDag-Erling Smørgravand \-1, respectively, if the buffer overflowed. 36949091c48SPoul-Henning Kamp.Pp 37081ae4b8dSRuslan ErmilovThe 37149091c48SPoul-Henning Kamp.Fn sbuf_copyin 37281ae4b8dSRuslan Ermilovfunction 37349091c48SPoul-Henning Kampreturns \-1 if copying string from userland failed, and number of bytes 37449091c48SPoul-Henning Kampcopied otherwise. 375863edaecSDag-Erling Smørgrav.Sh SEE ALSO 376863edaecSDag-Erling Smørgrav.Xr printf 3 , 377863edaecSDag-Erling Smørgrav.Xr strcat 3 , 378d68b700aSRuslan Ermilov.Xr strcpy 3 , 379d68b700aSRuslan Ermilov.Xr copyin 9 , 380e05f3134SAndrew R. Reiter.Xr copyinstr 9 , 381e05f3134SAndrew R. Reiter.Xr printf 9 382863edaecSDag-Erling Smørgrav.Sh HISTORY 383863edaecSDag-Erling SmørgravThe 38481ae4b8dSRuslan Ermilov.Nm 385863edaecSDag-Erling Smørgravfamily of functions first appeared in 38622cbe5e3SDag-Erling Smørgrav.Fx 4.4 . 387863edaecSDag-Erling Smørgrav.Sh AUTHORS 388863edaecSDag-Erling Smørgrav.An -nosplit 389863edaecSDag-Erling SmørgravThe 39081ae4b8dSRuslan Ermilov.Nm 391863edaecSDag-Erling Smørgravfamily of functions was designed by 392863edaecSDag-Erling Smørgrav.An Poul-Henning Kamp Aq phk@FreeBSD.org 393863edaecSDag-Erling Smørgravand implemented by 39409e06539SDag-Erling Smørgrav.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org . 395e499b74dSDag-Erling SmørgravAdditional improvements were suggested by 396e499b74dSDag-Erling Smørgrav.An Justin T. Gibbs Aq gibbs@FreeBSD.org . 397371c0c84SKelly YanceyAuto-extend support added by 398371c0c84SKelly Yancey.An Kelly Yancey Aq kbyanc@FreeBSD.org . 399863edaecSDag-Erling Smørgrav.Pp 400863edaecSDag-Erling SmørgravThis manual page was written by 40109e06539SDag-Erling Smørgrav.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org . 402