summaryrefslogtreecommitdiffstats
path: root/include/inn/qio.h
blob: 132da6fa168a83e27718eb2105cd29242fe68554 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*  $Id: qio.h 3653 2000-07-29 02:57:50Z rra $
**
**  Quick I/O package.
**
**  The interface to the Quick I/O package, optimized for reading through
**  files line by line.  This package uses internal buffering like stdio,
**  but is even more aggressive about its buffering.
*/

#ifndef INN_QIO_H
#define INN_QIO_H 1

#include <inn/defines.h>

BEGIN_DECLS

/*
**  State for a quick open file, equivalent to FILE for stdio.  All callers
**  should treat this structure as opaque and instead use the functions and
**  macros defined below.
*/
enum QIOflag { QIO_ok, QIO_error, QIO_long };

typedef struct {
    int         _fd;
    size_t      _length;        /* Length of the current string. */
    size_t      _size;          /* Size of the internal buffer. */
    char *      _buffer;
    char *      _start;         /* Start of the unread data. */
    char *      _end;           /* End of the available data. */
    off_t       _count;         /* Number of bytes read so far. */
    enum QIOflag _flag;
} QIOSTATE;

#define QIOerror(qp)    ((qp)->_flag != QIO_ok)
#define QIOtoolong(qp)  ((qp)->_flag == QIO_long)
#define QIOfileno(qp)   ((qp)->_fd)
#define QIOlength(qp)   ((qp)->_length)
#define QIOtell(qp)     ((qp)->_count - ((qp)->_end - (qp)->_start))

extern QIOSTATE *       QIOopen(const char *name);
extern QIOSTATE *       QIOfdopen(int fd);
extern char *           QIOread(QIOSTATE *qp);
extern void             QIOclose(QIOSTATE *qp);
extern int              QIOrewind(QIOSTATE *qp);

END_DECLS

#endif /* !INN_QIO_H */