Mercurial > libbuf
view buf.h @ 22:d87e84936795
misc: update copyright years
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 24 Feb 2021 11:43:50 +0100 |
parents | 939fe74cd80a |
children | b7690784cd17 |
line wrap: on
line source
/* * buf.h -- simple string buffer for C * * Copyright (c) 2019-2021 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. */ #ifndef BUF_H #define BUF_H #include <stdarg.h> #include <stddef.h> #if !defined(BUF_MALLOC) # define BUF_MALLOC malloc #endif #if !defined(BUF_REALLOC) # define BUF_REALLOC realloc #endif #if !defined(BUF_FREE) # define BUF_FREE free #endif #if defined(__cplusplus) extern "C" { #endif struct buf { char *data; size_t length; size_t capacity; }; void buf_init(struct buf *b); int buf_reserve(struct buf *b, size_t desired); int buf_resize(struct buf *b, size_t size, char c); int buf_shrink(struct buf *b); void buf_erase(struct buf *b, size_t pos, size_t count); int buf_putc(struct buf *b, char c); int buf_puts(struct buf *b, const char *s); int buf_printf(struct buf *b, const char *fmt, ...); int buf_vprintf(struct buf *b, const char *fmt, va_list ap); int buf_sub(struct buf *b, const struct buf *src, size_t pos, size_t count); int buf_dup(struct buf *b, const struct buf *src); void buf_clear(struct buf *b); void buf_finish(struct buf *b); #if defined(__cplusplus) } #endif #endif /* !BUF_H */