1321369Sdim/*- 2198090Srdivacky * Copyright (c) 2003-2006, Maxime Henrion <mux@FreeBSD.org> 3353358Sdim * All rights reserved. 4353358Sdim * 5353358Sdim * Redistribution and use in source and binary forms, with or without 6198090Srdivacky * modification, are permitted provided that the following conditions 7198090Srdivacky * are met: 8198090Srdivacky * 1. Redistributions of source code must retain the above copyright 9198090Srdivacky * notice, this list of conditions and the following disclaimer. 10198090Srdivacky * 2. Redistributions in binary form must reproduce the above copyright 11198090Srdivacky * notice, this list of conditions and the following disclaimer in the 12198090Srdivacky * documentation and/or other materials provided with the distribution. 13198090Srdivacky * 14198090Srdivacky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15321369Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16221345Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17221345Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18221345Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19341825Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20321369Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21198090Srdivacky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22198090Srdivacky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23341825Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24341825Sdim * SUCH DAMAGE. 25341825Sdim * 26341825Sdim * $FreeBSD$ 27341825Sdim */ 28341825Sdim#ifndef _STREAM_H_ 29341825Sdim#define _STREAM_H_ 30341825Sdim 31198090Srdivacky#include "misc.h" 32221345Sdim 33198090Srdivacky/* Stream filters. */ 34218893Sdimtypedef enum { 35276479Sdim STREAM_FILTER_NULL, 36280031Sdim STREAM_FILTER_ZLIB, 37198090Srdivacky STREAM_FILTER_MD5, 38198090Srdivacky STREAM_FILTER_MD5RCS 39198090Srdivacky} stream_filter_t; 40226633Sdim 41226633Sdimstruct stream; 42226633Sdimstruct buf; 43198090Srdivacky 44198090Srdivackytypedef ssize_t stream_readfn_t(void *, void *, size_t); 45198090Srdivackytypedef ssize_t stream_writefn_t(void *, const void *, size_t); 46198090Srdivackytypedef int stream_closefn_t(void *); 47198090Srdivacky 48198090Srdivacky/* Convenience functions for handling file descriptors. */ 49198090Srdivackystream_readfn_t stream_read_fd; 50198090Srdivackystream_writefn_t stream_write_fd; 51280031Sdimstream_closefn_t stream_close_fd; 52341825Sdim 53341825Sdim/* Convenience functions for handling character buffers. */ 54198090Srdivackystream_readfn_t stream_read_buf; 55276479Sdimstream_writefn_t stream_append_buf; 56276479Sdimstream_closefn_t stream_close_buf; 57276479Sdim 58276479Sdimstruct stream *stream_open(void *, stream_readfn_t *, stream_writefn_t *, 59276479Sdim stream_closefn_t *); 60276479Sdimstruct stream *stream_open_fd(int, stream_readfn_t *, stream_writefn_t *, 61276479Sdim stream_closefn_t *); 62276479Sdimstruct stream *stream_open_buf(struct buf *); 63276479Sdimstruct stream *stream_open_file(const char *, int, ...); 64276479Sdimint stream_fileno(struct stream *); 65276479Sdimssize_t stream_read(struct stream *, void *, size_t); 66276479Sdimssize_t stream_read_blocking(struct stream *, void *, size_t); 67276479Sdimssize_t stream_write(struct stream *, const void *, size_t); 68309124Sdimchar *stream_getln(struct stream *, size_t *); 69198090Srdivackyint stream_printf(struct stream *, const char *, ...) 70198090Srdivacky __printflike(2, 3); 71321369Sdimint stream_flush(struct stream *); 72221345Sdimint stream_sync(struct stream *); 73353358Sdimint stream_truncate(struct stream *, off_t); 74353358Sdimvoid stream_truncate_buf(struct buf *, off_t); 75353358Sdimint stream_truncate_rel(struct stream *, off_t); 76353358Sdimint stream_rewind(struct stream *); 77280031Sdimint stream_eof(struct stream *); 78280031Sdimint stream_close(struct stream *); 79280031Sdimint stream_filter_start(struct stream *, stream_filter_t, void *); 80280031Sdimvoid stream_filter_stop(struct stream *); 81221345Sdim 82221345Sdimstruct buf *buf_new(size_t); 83221345Sdimvoid buf_free(struct buf *); 84221345Sdim#endif /* !_STREAM_H_ */ 85221345Sdim