1qio(3)                    InterNetNews Documentation                    qio(3)
2
3
4

NAME

6       qio - Quick I/O routines for reading files
7

SYNOPSIS

9           #include <inn/qio.h>
10
11           QIOSTATE *QIOopen(const char *name);
12
13           QIOSTATE *QIOfdopen(int> I<fd);
14
15           void QIOclose(QIOSTATE *qp);
16
17           char *QIOread(QIOSTATE *qp);
18
19           int QIOfileno(QIOSTATE *qp);
20
21           size_t QIOlength(QIOSTATE *qp);
22
23           int QIOrewind(QIOSTATE *qp);
24
25           off_t QIOtell(QIOSTATE *qp);
26
27           bool QIOerror(QIOSTATE *qp);
28
29           bool QIOtoolong(QIOSTATE *qp);
30

DESCRIPTION

32       The routines described in this manual page are part of libinn(3).  They
33       are used to provide quick read access to files; the QIO routines use
34       buffering adapted to the block size of the device, similar to stdio,
35       but with a more convenient syntax for reading newline-terminated lines.
36       QIO is short for "Quick I/O" (a bit of a misnomer, as QIO provides
37       read-only access to files only).
38
39       The QIOSTATE structure returned by QIOopen and QIOfdopen is the analog
40       to stdio's FILE structure and should be treated as a black box by all
41       users of these routines.  Only the above API should be used.
42
43       QIOopen opens the given file for reading.  For regular files, if your
44       system provides that information and the size is reasonable, QIO will
45       use the block size of the underlying file system as its buffer size;
46       otherwise, it will default to a buffer of 8 KB.  Returns a pointer to
47       use for subsequent calls, or NULL on error.  QIOfdopen performs the
48       same operation except on an already-open file descriptor (fd must
49       designate a file open for reading).
50
51       QIOclose closes the open file and releases any resources used by the
52       QIOSTATE structure.  The QIOSTATE pointer should not be used again
53       after it has been passed to this function.
54
55       QIOread reads the next newline-terminated line in the file and returns
56       a pointer to it, with the trailing newline replaced by nul.  The
57       returned pointer is a pointer into a buffer in the QIOSTATE object and
58       therefore will remain valid until QIOclose is called on that object.
59       If EOF is reached, an error occurs, or if the line is longer than the
60       buffer size, NULL is returned instead.  To distinguish between the
61       error cases, use QIOerror and QIOtoolong.
62
63       QIOfileno returns the descriptor of the open file.
64
65       QIOlength returns the length in bytes of the last line returned by
66       QIOread.  Its return value is only defined after a successful call to
67       QIOread.
68
69       QIOrewind sets the read pointer back to the beginning of the file and
70       reads the first block of the file in anticipation of future reads.  It
71       returns 0 if successful and -1 on error.
72
73       QIOtell returns the current value of the read pointer (the lseek(2)
74       offset at which the next line will start).
75
76       QIOerror returns true if there was an error in the last call to
77       QIOread, false otherwise.  QIOtoolong returns true if there was an
78       error and the error was that the line was too long.  If QIOread returns
79       NULL, these functions should be called to determine what happened.  If
80       QIOread returned NULL and QIOerror is false, EOF was reached.  Note
81       that if QIOtoolong returns true, the next call to QIOread will try to
82       read the remainder of the line and will likely return a partial line;
83       users of this library should in general treat long lines as fatal
84       errors.
85

EXAMPLES

87       This block of code opens /etc/motd and reads it a line at a time,
88       printing out each line preceded by its offset in the file.
89
90           QIOSTATE *qp;
91           off_t offset;
92           char *p;
93
94           qp = QIOopen("/etc/motd");
95           if (qp == NULL) {
96               perror("Open error");
97               exit(1);
98           }
99           for (p = QIOread(qp); p != NULL; p = QIOread(qp))
100               printf("%ld: %s\n", (unsigned long) QIOtell(qp), p);
101           if (QIOerror(qp)) {
102               perror("Read error");
103               exit(1);
104           }
105           QIOclose(qp);
106

HISTORY

108       Written by Rich $alz <rsalz@uunet.uu.net> for InterNetNews.  Updated by
109       Russ Allbery <eagle@eyrie.org>.
110
111       $Id: qio.pod 9767 2014-12-07 21:13:43Z iulius $
112
113
114
115INN 2.6.3                         2015-09-12                            qio(3)
Impressum