1 /* ====================================================================
2 * Copyright (c) 1996,1997 The Apache Group. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the Apache Group
19 * for use in the Apache HTTP server project (http://www.apache.org/)."
21 * 4. The names "Apache Server" and "Apache Group" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission.
25 * 5. Redistributions of any form whatsoever must retain the following
27 * "This product includes software developed by the Apache Group
28 * for use in the Apache HTTP server project (http://www.apache.org/)."
30 * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
31 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
34 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
41 * OF THE POSSIBILITY OF SUCH DAMAGE.
42 * ====================================================================
44 * This software consists of voluntary contributions made by many
45 * individuals on behalf of the Apache Group and was originally based
46 * on public domain software written at the National Center for
47 * Supercomputing Applications, University of Illinois, Urbana-Champaign.
48 * For more information on the Apache Group and the Apache HTTP server
49 * project, please see <http://www.apache.org/>.
55 /* Reading is buffered */
57 /* Writing is buffered */
60 /* At end of file, or closed stream; no further input allowed */
62 /* No further output possible */
64 /* A read error has occurred */
66 /* A write error has occurred */
68 #ifdef B_ERROR /* in SVR4: sometimes defined in /usr/include/sys/buf.h */
69 #undef B_ERROR /* avoid "warning: `B_ERROR' redefined" */
72 /* Use chunked writing */
74 /* bflush() if a read would block */
75 #define B_SAFEREAD (128)
77 typedef struct buff_struct BUFF
;
80 int flags
; /* flags */
81 unsigned char *inptr
; /* pointer to next location to read */
82 int incnt
; /* number of bytes left to read from input buffer;
83 * always 0 if had a read error */
84 int outchunk
; /* location of chunk header when chunking */
85 int outcnt
; /* number of byte put in output buffer */
86 unsigned char *inbase
;
87 unsigned char *outbase
;
89 void (*error
) (BUFF
* fb
, int op
, void *data
);
91 long int bytes_sent
; /* number of bytes actually written */
95 /* could also put pointers to the basic I/O routines here */
96 int fd
; /* the file descriptor */
97 int fd_in
; /* input file descriptor, if different */
100 /* Options to bset/getopt */
101 #define BO_BYTECT (1)
103 /* Stream creation and modification */
104 extern BUFF
*bcreate(pool
* p
, int flags
);
105 extern void bpushfd(BUFF
* fb
, int fd_in
, int fd_out
);
106 extern int bsetopt(BUFF
* fb
, int optname
, const void *optval
);
107 extern int bgetopt(BUFF
* fb
, int optname
, void *optval
);
108 extern int bsetflag(BUFF
* fb
, int flag
, int value
);
109 extern int bclose(BUFF
* fb
);
111 #define bgetflag(fb, flag) ((fb)->flags & (flag))
114 extern void bonerror(BUFF
* fb
, void (*error
) (BUFF
*, int, void *),
118 extern int bread(BUFF
* fb
, void *buf
, int nbyte
);
119 extern int bgets(char *s
, int n
, BUFF
* fb
);
120 extern int blookc(char *buff
, BUFF
* fb
);
121 extern int bskiplf(BUFF
* fb
);
122 extern int bwrite(BUFF
* fb
, const void *buf
, int nbyte
);
123 extern int bflush(BUFF
* fb
);
124 extern int bputs(const char *x
, BUFF
* fb
);
125 extern int bvputs(BUFF
* fb
, ...);
126 extern int bprintf(BUFF
* fb
, const char *fmt
, ...);
127 extern int vbprintf(BUFF
* fb
, const char *fmt
, va_list vlist
);
129 /* Internal routines */
130 extern int bflsbuf(int c
, BUFF
* fb
);
131 extern int bfilbuf(BUFF
* fb
);
133 #define bgetc(fb) ( ((fb)->incnt == 0) ? bfilbuf(fb) : \
134 ((fb)->incnt--, *((fb)->inptr++)) )
136 #define bputc(c, fb) ((((fb)->flags & (B_EOUT|B_WRERR|B_WR)) != B_WR || \
137 (fb)->outcnt == (fb)->bufsiz) ? bflsbuf(c, (fb)) : \
138 ((fb)->outbase[(fb)->outcnt++] = (c), 0))