view libbuf.3 @ 37:ab071d485d38 default tip @

misc: update copyright years
author David Demelier <markand@malikania.fr>
date Thu, 04 Jan 2024 10:42:26 +0100
parents 5493466d6e56
children
line wrap: on
line source

.\"
.\" libbuf.3 -- simple string buffer for C
.\"
.\" Copyright (c) 2019-2024 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-2022
.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 int
.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 int
.Fn buf_init "struct buf *b"
.Ft int
.Fn buf_printf "struct buf *b" "const char *fmt" "..."
.Ft int
.Fn buf_putc "struct buf *b" "char c"
.Ft int
.Fn buf_puts "struct buf *b" "const char *s"
.Ft int
.Fn buf_reserve "struct buf *b" "size_t desired"
.Ft int
.Fn buf_resize "struct buf *b" "size_t desired" "char c"
.Ft int
.Fn buf_shrink "struct buf *b"
.Ft int
.Fn buf_sub "struct buf *b" "const struct buf *src" "size_t pos" "size_t count"
.Ft int
.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 (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>