FreeBSD kernel kern code
subr_sbuf.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/ctype.h>
#include <sys/errno.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/systm.h>
#include <sys/uio.h>
#include <machine/stdarg.h>
#include <sys/sbuf.h>
Include dependency graph for subr_sbuf.c:

Go to the source code of this file.

Macros

#define SBMALLOC(size)   malloc(size, M_SBUF, M_WAITOK)
 
#define SBFREE(buf)   free(buf, M_SBUF)
 
#define SBUF_ISDYNAMIC(s)   ((s)->s_flags & SBUF_DYNAMIC)
 
#define SBUF_ISDYNSTRUCT(s)   ((s)->s_flags & SBUF_DYNSTRUCT)
 
#define SBUF_ISFINISHED(s)   ((s)->s_flags & SBUF_FINISHED)
 
#define SBUF_HASROOM(s)   ((s)->s_len < (s)->s_size - 1)
 
#define SBUF_FREESPACE(s)   ((s)->s_size - ((s)->s_len + 1))
 
#define SBUF_CANEXTEND(s)   ((s)->s_flags & SBUF_AUTOEXTEND)
 
#define SBUF_ISSECTION(s)   ((s)->s_flags & SBUF_INSECTION)
 
#define SBUF_SETFLAG(s, f)   do { (s)->s_flags |= (f); } while (0)
 
#define SBUF_CLEARFLAG(s, f)   do { (s)->s_flags &= ~(f); } while (0)
 
#define SBUF_MINEXTENDSIZE   16 /* Should be power of 2. */
 
#define SBUF_MAXEXTENDSIZE   4096
 
#define SBUF_MAXEXTENDINCR   4096
 
#define assert_sbuf_integrity(s)   do { } while (0)
 
#define assert_sbuf_state(s, i)   do { } while (0)
 

Functions

 __FBSDID ("$BSDSUniX$")
 
static MALLOC_DEFINE (M_SBUF,"sbuf","string buffers")
 
static int sbuf_extendsize (int size)
 
static int sbuf_extend (struct sbuf *s, int addlen)
 
static struct sbuf * sbuf_newbuf (struct sbuf *s, char *buf, int length, int flags)
 
struct sbuf * sbuf_new (struct sbuf *s, char *buf, int length, int flags)
 
struct sbuf * sbuf_uionew (struct sbuf *s, struct uio *uio, int *error)
 
void sbuf_clear (struct sbuf *s)
 
int sbuf_setpos (struct sbuf *s, ssize_t pos)
 
void sbuf_set_drain (struct sbuf *s, sbuf_drain_func *func, void *ctx)
 
static int sbuf_drain (struct sbuf *s)
 
static void sbuf_put_byte (struct sbuf *s, int c)
 
int sbuf_bcat (struct sbuf *s, const void *buf, size_t len)
 
int sbuf_bcopyin (struct sbuf *s, const void *uaddr, size_t len)
 
int sbuf_bcpy (struct sbuf *s, const void *buf, size_t len)
 
int sbuf_cat (struct sbuf *s, const char *str)
 
int sbuf_copyin (struct sbuf *s, const void *uaddr, size_t len)
 
int sbuf_cpy (struct sbuf *s, const char *str)
 
static void sbuf_putc_func (int c, void *arg)
 
int sbuf_vprintf (struct sbuf *s, const char *fmt, va_list ap)
 
int sbuf_printf (struct sbuf *s, const char *fmt,...)
 
int sbuf_putc (struct sbuf *s, int c)
 
int sbuf_trim (struct sbuf *s)
 
int sbuf_error (const struct sbuf *s)
 
int sbuf_finish (struct sbuf *s)
 
char * sbuf_data (struct sbuf *s)
 
ssize_t sbuf_len (struct sbuf *s)
 
void sbuf_delete (struct sbuf *s)
 
int sbuf_done (const struct sbuf *s)
 
void sbuf_start_section (struct sbuf *s, ssize_t *old_lenp)
 
ssize_t sbuf_end_section (struct sbuf *s, ssize_t old_len, size_t pad, int c)
 

Macro Definition Documentation

#define assert_sbuf_state (   s,
 
)    do { } while (0)
#define SBFREE (   buf)    free(buf, M_SBUF)

Definition at line 56 of file subr_sbuf.c.

Referenced by sbuf_delete(), sbuf_extend(), and sbuf_new().

#define SBMALLOC (   size)    malloc(size, M_SBUF, M_WAITOK)

Definition at line 55 of file subr_sbuf.c.

Referenced by sbuf_extend(), sbuf_new(), and sbuf_newbuf().

#define SBUF_CANEXTEND (   s)    ((s)->s_flags & SBUF_AUTOEXTEND)

Definition at line 71 of file subr_sbuf.c.

Referenced by sbuf_extend().

#define SBUF_CLEARFLAG (   s,
 
)    do { (s)->s_flags &= ~(f); } while (0)

Definition at line 78 of file subr_sbuf.c.

Referenced by sbuf_clear(), and sbuf_end_section().

#define SBUF_FREESPACE (   s)    ((s)->s_size - ((s)->s_len + 1))

Definition at line 70 of file subr_sbuf.c.

Referenced by sbuf_bcopyin(), sbuf_copyin(), and sbuf_put_byte().

#define SBUF_HASROOM (   s)    ((s)->s_len < (s)->s_size - 1)

Definition at line 69 of file subr_sbuf.c.

#define SBUF_ISDYNAMIC (   s)    ((s)->s_flags & SBUF_DYNAMIC)

Definition at line 66 of file subr_sbuf.c.

Referenced by sbuf_delete(), and sbuf_extend().

#define SBUF_ISDYNSTRUCT (   s)    ((s)->s_flags & SBUF_DYNSTRUCT)

Definition at line 67 of file subr_sbuf.c.

Referenced by sbuf_delete().

#define SBUF_ISFINISHED (   s)    ((s)->s_flags & SBUF_FINISHED)

Definition at line 68 of file subr_sbuf.c.

Referenced by sbuf_done().

#define SBUF_ISSECTION (   s)    ((s)->s_flags & SBUF_INSECTION)
#define SBUF_MAXEXTENDINCR   4096

Definition at line 87 of file subr_sbuf.c.

Referenced by sbuf_extendsize().

#define SBUF_MAXEXTENDSIZE   4096

Definition at line 86 of file subr_sbuf.c.

Referenced by sbuf_extendsize().

#define SBUF_MINEXTENDSIZE   16 /* Should be power of 2. */

Definition at line 80 of file subr_sbuf.c.

Referenced by sbuf_extendsize().

#define SBUF_SETFLAG (   s,
 
)    do { (s)->s_flags |= (f); } while (0)

Definition at line 77 of file subr_sbuf.c.

Referenced by sbuf_extend(), sbuf_finish(), sbuf_new(), sbuf_newbuf(), and sbuf_start_section().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
static MALLOC_DEFINE ( M_SBUF  ,
"sbuf"  ,
"string buffers"   
)
static
int sbuf_bcopyin ( struct sbuf *  s,
const void *  uaddr,
size_t  len 
)

Definition at line 412 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, sbuf_extend(), and SBUF_FREESPACE.

Here is the call graph for this function:

int sbuf_bcpy ( struct sbuf *  s,
const void *  buf,
size_t  len 
)

Definition at line 441 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, sbuf_bcat(), and sbuf_clear().

Here is the call graph for this function:

int sbuf_cat ( struct sbuf *  s,
const char *  str 
)

Definition at line 455 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, and sbuf_put_byte().

Referenced by sbuf_cpy(), and sys_abort2().

Here is the call graph for this function:

Here is the caller graph for this function:

void sbuf_clear ( struct sbuf *  s)

Definition at line 269 of file subr_sbuf.c.

References assert_sbuf_integrity, and SBUF_CLEARFLAG.

Referenced by sbuf_bcpy(), sbuf_cpy(), sys_abort2(), sysctl_debug_witness_badstacks(), sysctl_kern_console(), and vfs_mountroot().

Here is the caller graph for this function:

int sbuf_copyin ( struct sbuf *  s,
const void *  uaddr,
size_t  len 
)

Definition at line 477 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, sbuf_extend(), SBUF_FREESPACE, and SBUF_ISSECTION.

Referenced by sys_abort2().

Here is the call graph for this function:

Here is the caller graph for this function:

int sbuf_cpy ( struct sbuf *  s,
const char *  str 
)

Definition at line 517 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, sbuf_cat(), and sbuf_clear().

Referenced by cpufreq_levels_sysctl(), and cpufreq_settings_sysctl().

Here is the call graph for this function:

Here is the caller graph for this function:

char* sbuf_data ( struct sbuf *  s)
int sbuf_done ( const struct sbuf *  s)

Definition at line 772 of file subr_sbuf.c.

References SBUF_ISFINISHED.

static int sbuf_drain ( struct sbuf *  s)
static

Definition at line 326 of file subr_sbuf.c.

Referenced by sbuf_finish(), and sbuf_put_byte().

Here is the caller graph for this function:

ssize_t sbuf_end_section ( struct sbuf *  s,
ssize_t  old_len,
size_t  pad,
int  c 
)

Definition at line 807 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, SBUF_CLEARFLAG, SBUF_ISSECTION, and sbuf_put_byte().

Referenced by corehdr(), and putnote().

Here is the call graph for this function:

Here is the caller graph for this function:

int sbuf_error ( const struct sbuf *  s)

Definition at line 684 of file subr_sbuf.c.

Referenced by expand_name().

Here is the caller graph for this function:

static int sbuf_extend ( struct sbuf *  s,
int  addlen 
)
static

Definition at line 152 of file subr_sbuf.c.

References SBFREE, SBMALLOC, SBUF_CANEXTEND, sbuf_extendsize(), SBUF_ISDYNAMIC, and SBUF_SETFLAG.

Referenced by sbuf_bcopyin(), sbuf_copyin(), and sbuf_put_byte().

Here is the call graph for this function:

Here is the caller graph for this function:

static int sbuf_extendsize ( int  size)
static

Definition at line 133 of file subr_sbuf.c.

References SBUF_MAXEXTENDINCR, SBUF_MAXEXTENDSIZE, and SBUF_MINEXTENDSIZE.

Referenced by sbuf_extend(), and sbuf_newbuf().

Here is the caller graph for this function:

ssize_t sbuf_len ( struct sbuf *  s)

Definition at line 736 of file subr_sbuf.c.

References assert_sbuf_integrity.

Referenced by cpufreq_levels_sysctl(), cpufreq_settings_sysctl(), expand_name(), fail_point_sysctl(), mount_argf(), sysctl_debug_witness_badstacks(), and sysctl_kern_console().

Here is the caller graph for this function:

struct sbuf* sbuf_new ( struct sbuf *  s,
char *  buf,
int  length,
int  flags 
)
static struct sbuf* sbuf_newbuf ( struct sbuf *  s,
char *  buf,
int  length,
int  flags 
)
static

Definition at line 179 of file subr_sbuf.c.

References buf, SBMALLOC, sbuf_extendsize(), and SBUF_SETFLAG.

Referenced by sbuf_new().

Here is the call graph for this function:

Here is the caller graph for this function:

int sbuf_printf ( struct sbuf *  s,
const char *  fmt,
  ... 
)
static void sbuf_put_byte ( struct sbuf *  s,
int  c 
)
static

Definition at line 360 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, sbuf_drain(), sbuf_extend(), SBUF_FREESPACE, and SBUF_ISSECTION.

Referenced by sbuf_bcat(), sbuf_cat(), sbuf_end_section(), sbuf_putc(), and sbuf_putc_func().

Here is the call graph for this function:

Here is the caller graph for this function:

int sbuf_putc ( struct sbuf *  s,
int  c 
)

Definition at line 647 of file subr_sbuf.c.

References sbuf_put_byte().

Referenced by expand_name().

Here is the call graph for this function:

Here is the caller graph for this function:

static void sbuf_putc_func ( int  c,
void *  arg 
)
static

Definition at line 537 of file subr_sbuf.c.

References sbuf_put_byte().

Referenced by sbuf_vprintf().

Here is the call graph for this function:

Here is the caller graph for this function:

void sbuf_set_drain ( struct sbuf *  s,
sbuf_drain_func *  func,
void *  ctx 
)

Definition at line 311 of file subr_sbuf.c.

References assert_sbuf_integrity, and assert_sbuf_state.

Referenced by corehdr(), note_procstat_auxv(), note_procstat_files(), note_procstat_vmmap(), and sbuf_new_for_sysctl().

Here is the caller graph for this function:

int sbuf_setpos ( struct sbuf *  s,
ssize_t  pos 
)

Definition at line 286 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, and SBUF_ISSECTION.

void sbuf_start_section ( struct sbuf *  s,
ssize_t *  old_lenp 
)

Definition at line 782 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, SBUF_ISSECTION, and SBUF_SETFLAG.

Referenced by corehdr(), and putnote().

Here is the caller graph for this function:

int sbuf_trim ( struct sbuf *  s)

Definition at line 660 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, and SBUF_ISSECTION.

Referenced by cpufreq_levels_sysctl(), cpufreq_settings_sysctl(), fail_point_sysctl(), and sys_abort2().

Here is the caller graph for this function:

struct sbuf* sbuf_uionew ( struct sbuf *  s,
struct uio *  uio,
int *  error 
)

Definition at line 239 of file subr_sbuf.c.

References sbuf_delete(), SBUF_ISSECTION, sbuf_new(), and uiomove().

Here is the call graph for this function:

int sbuf_vprintf ( struct sbuf *  s,
const char *  fmt,
va_list  ap 
)

Definition at line 545 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, kvprintf(), and sbuf_putc_func().

Referenced by mount_argf(), and sbuf_printf().

Here is the call graph for this function:

Here is the caller graph for this function: