view libbuf.3 @ 0:b1991ee4451d

misc: initial import
author David Demelier <markand@malikania.fr>
date Thu, 29 Oct 2020 17:24:30 +0100
parents
children 3665a56a00aa
line wrap: on
line source

.\"
.\" libbuf.3 -- simple string buffer for C
.\"
.\" Copyright (c) 2019-2020 David Demelier <markand@malikania.fr>
.\"
.\" Permission to use, copy, modify, and/or distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd October 29, 2019-2020
.Dt LIBBUF 3
.Os
.\" NAME
.Sh NAME
.Nm libbuf
.Nd minimal dynamic string library
.\" LIBRARY
.Sh LIBRARY
libbuf (libbuf, -lbuf)
.\" SYNOPSIS
.Sh SYNOPSIS
.In buf.h
.Ft void
.Fn buf_clear "struct buf *b"
.Ft bool
.Fn buf_dup "struct buf *b" "const struct buf *src"
.Ft void
.Fn buf_erase "struct buf *b" "size_t pos" "size_t count"
.Ft void
.Fn buf_finish "struct buf *b"
.Ft bool
.Fn buf_init "struct buf *b"
.Ft bool
.Fn buf_printf "struct buf *b" "const char *fmt" "..."
.Ft bool
.Fn buf_putc "struct buf *b" "char c"
.Ft bool
.Fn buf_puts "struct buf *b" "const char *s"
.Ft bool
.Fn buf_reserve "struct buf *b" "size_t desired"
.Ft bool
.Fn buf_resize "struct buf *b" "size_t desired" "char c"
.Ft bool
.Fn buf_shrink "struct buf *b"
.Ft bool
.Fn buf_sub "struct buf *b" "const struct buf *src" "size_t pos" "size_t count"
.Ft bool
.Fn buf_vprintf "struct buf *b" "const char *fmt" "va_list ap"
.\" DESCRIPTION
.Sh DESCRIPTION
The
.Nm
library is a general purpose string library for C.
.Pp
It automatically expands storage as required.
It will first try to allocate twice as the current storage space until enough
room is available or in case it would exceed maximum storage it will grow with
minimal required storage.
.Pp
Every function expects as first argument a buffer to work with which can never
be NULL.
.Pp
The
.Vt "struct buf"
is a publicly exposed structure with the following fields:
.Bl -tag -width "capacity"
.It Va data
.Va (const char *)
The current NUL-terminated C string, maybe NULL if the buffer isn't initialized.
.It Va length
.Va (size_t)
The data length.
.It Va capacity
.Va (size_t)
The real capacity available for writing characters (not including NUL). A
capacity of 5 means you can write 5 characters plus the NUL terminator without
reallocating.
.El
.\" SEE ALSO
.Sh SEE ALSO
.Xr buf_clear 3 ,
.Xr buf_dup 3 ,
.Xr buf_erase 3 ,
.Xr buf_finish 3 ,
.Xr buf_init 3 ,
.Xr buf_printf 3 ,
.Xr buf_putc 3 ,
.Xr buf_puts 3 ,
.Xr buf_reserve 3 ,
.Xr buf_resize 3 ,
.Xr buf_shrink 3 ,
.Xr buf_sub 3 ,
.Xr buf_vprintf 3
.\" AUTHORS
.Sh AUTHORS
The
.Nm
library was written by
.An David Demelier <markand@malikania.fr>