1*ef21cefbSnicm /* $OpenBSD: buf.h,v 1.13 2011/07/06 15:36:52 nicm Exp $ */ 22dc36bedSjoris /* 32dc36bedSjoris * Copyright (c) 2003 Jean-Francois Brousseau <jfb@openbsd.org> 42dc36bedSjoris * All rights reserved. 52dc36bedSjoris * 62dc36bedSjoris * Redistribution and use in source and binary forms, with or without 72dc36bedSjoris * modification, are permitted provided that the following conditions 82dc36bedSjoris * are met: 92dc36bedSjoris * 102dc36bedSjoris * 1. Redistributions of source code must retain the above copyright 112dc36bedSjoris * notice, this list of conditions and the following disclaimer. 122dc36bedSjoris * 2. The name of the author may not be used to endorse or promote products 132dc36bedSjoris * derived from this software without specific prior written permission. 142dc36bedSjoris * 152dc36bedSjoris * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 162dc36bedSjoris * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 172dc36bedSjoris * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 182dc36bedSjoris * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 192dc36bedSjoris * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 202dc36bedSjoris * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 212dc36bedSjoris * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 222dc36bedSjoris * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 232dc36bedSjoris * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 242dc36bedSjoris * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 252dc36bedSjoris * 262dc36bedSjoris * Buffer management 272dc36bedSjoris * ----------------- 282dc36bedSjoris * 292dc36bedSjoris * This code provides an API to generic memory buffer management. All 307bb3ddb0Sray * operations are performed on a buf structure, which is kept opaque to the 312dc36bedSjoris * API user in order to avoid corruption of the fields and make sure that only 322dc36bedSjoris * the internals can modify the fields. 332dc36bedSjoris * 347bb3ddb0Sray * The first step is to allocate a new buffer using the buf_alloc() 352dc36bedSjoris * function, which returns a pointer to a new buffer. 362dc36bedSjoris */ 372dc36bedSjoris 382dc36bedSjoris #ifndef BUF_H 392dc36bedSjoris #define BUF_H 402dc36bedSjoris 414781e2faSxsa #include <sys/types.h> 424781e2faSxsa 437bb3ddb0Sray typedef struct buf BUF; 442dc36bedSjoris 450ee14128Sray BUF *buf_alloc(size_t); 460ee14128Sray BUF *buf_load(const char *); 477bb3ddb0Sray void buf_free(BUF *); 487bb3ddb0Sray void *buf_release(BUF *); 497bb3ddb0Sray u_char buf_getc(BUF *, size_t); 507bb3ddb0Sray void buf_empty(BUF *); 517bb3ddb0Sray size_t buf_append(BUF *, const void *, size_t); 527bb3ddb0Sray void buf_putc(BUF *, int); 53*ef21cefbSnicm void buf_puts(BUF *b, const char *str); 547bb3ddb0Sray size_t buf_len(BUF *); 557bb3ddb0Sray int buf_write_fd(BUF *, int); 567bb3ddb0Sray int buf_write(BUF *, const char *, mode_t); 577bb3ddb0Sray void buf_write_stmp(BUF *, char *); 587bb3ddb0Sray u_char *buf_get(BUF *b); 59*ef21cefbSnicm 602dc36bedSjoris #endif /* BUF_H */ 61