7 /* record interface to stream-lf files
9 /* #include <rec_streamlf.h>
11 /* int rec_streamlf_get(stream, buf, maxlen)
16 /* int rec_streamlf_put(stream, type, data, len)
21 /* AUXILIARY FUNCTIONS
22 /* int REC_STREAMLF_PUT_BUF(stream, type, buf)
27 /* This module implements record I/O on top of stream-lf files.
29 /* rec_streamlf_get() reads one record from the specified stream.
30 /* The result is null-terminated and may contain embedded null
32 /* The \fImaxlen\fR argument specifies an upper bound to the amount
33 /* of data read. The result is REC_TYPE_NORM when the record was
34 /* terminated by newline, REC_TYPE_CONT when no terminating newline
35 /* was found (the record was larger than \fImaxlen\fR characters or
36 /* EOF was reached), and REC_TYPE_EOF when no data could be read or
37 /* when an I/O error was detected.
39 /* rec_streamlf_put() writes one record to the named stream.
40 /* When the record type is REC_TYPE_NORM, a newline character is
41 /* appended to the output. The result is the record type, or
42 /* REC_TYPE_EOF in case of problems.
44 /* REC_STREAMLF_PUT_BUF() is a wrapper for rec_streamlf_put() that
45 /* makes it more convenient to output VSTRING buffers.
46 /* REC_STREAMLF_PUT_BUF() is an unsafe macro that evaluates some
47 /* arguments more than once.
49 /* record(3) typed records
53 /* The Secure Mailer license must be distributed with this software.
56 /* IBM T.J. Watson Research
58 /* Yorktown Heights, NY 10598, USA
65 /* Utility library. */
74 #include <rec_streamlf.h>
76 /* rec_streamlf_get - read record from stream-lf file */
78 int rec_streamlf_get(VSTREAM
*stream
, VSTRING
*buf
, int maxlen
)
84 * If this one character ar a time code proves to be a performance
85 * bottleneck, switch to block search (memchr()) and to block move
86 * (memcpy()) operations.
90 if ((ch
= VSTREAM_GETC(stream
)) == VSTREAM_EOF
)
91 return (VSTRING_LEN(buf
) > 0 ? REC_TYPE_CONT
: REC_TYPE_EOF
);
93 VSTRING_TERMINATE(buf
);
94 return (REC_TYPE_NORM
);
96 VSTRING_ADDCH(buf
, ch
);
98 VSTRING_TERMINATE(buf
);
99 return (REC_TYPE_CONT
);
102 /* rec_streamlf_put - write record to stream-lf file */
104 int rec_streamlf_put(VSTREAM
*stream
, int type
, const char *data
, int len
)
107 (void) vstream_fwrite(stream
, data
, len
);
108 if (type
== REC_TYPE_NORM
)
109 (void) VSTREAM_PUTC('\n', stream
);
110 return (vstream_ferror(stream
) ? REC_TYPE_EOF
: type
);