1/*	$NetBSD$	*/
2
3#ifndef _RECORD_H_INCLUDED_
4#define _RECORD_H_INCLUDED_
5
6/*++
7/* NAME
8/*	record 3h
9/* SUMMARY
10/*	simple typed record I/O
11/* SYNOPSIS
12/*	#include <record.h>
13/* DESCRIPTION
14/* .nf
15
16 /*
17  * System library.
18  */
19#include <stdarg.h>
20
21 /*
22  * Utility library.
23  */
24#include <vstring.h>
25#include <vstream.h>
26
27 /*
28  * Record type values are positive numbers 0..255. Negative record type
29  * values are reserved for diagnostics.
30  */
31#define REC_TYPE_EOF	-1		/* no record */
32#define REC_TYPE_ERROR	-2		/* bad record */
33
34 /*
35  * Functional interface.
36  */
37extern int rec_get_raw(VSTREAM *, VSTRING *, ssize_t, int);
38extern int rec_put(VSTREAM *, int, const char *, ssize_t);
39extern int rec_put_type(VSTREAM *, int, off_t);
40extern int PRINTFLIKE(3, 4) rec_fprintf(VSTREAM *, int, const char *,...);
41extern int rec_fputs(VSTREAM *, int, const char *);
42extern int rec_goto(VSTREAM *, const char *);
43extern int rec_pad(VSTREAM *, int, int);
44
45#define REC_PUT_BUF(v, t, b) rec_put((v), (t), vstring_str(b), VSTRING_LEN(b))
46
47#define REC_FLAG_NONE	(0)
48#define REC_FLAG_FOLLOW_PTR	(1<<0)	/* follow PTR records */
49#define REC_FLAG_SKIP_DTXT	(1<<1)	/* skip DTXT records */
50#define REC_FLAG_SEEK_END	(1<<2)	/* seek EOF after END record */
51
52#define REC_FLAG_DEFAULT \
53	(REC_FLAG_FOLLOW_PTR | REC_FLAG_SKIP_DTXT | REC_FLAG_SEEK_END)
54
55#define REC_GET_HIDDEN_TYPE(t) \
56	((t) == REC_TYPE_PTR || (t) == REC_TYPE_DTXT)
57
58#define rec_get(fp, buf, limit) \
59	rec_get_raw((fp), (buf), (limit), REC_FLAG_DEFAULT)
60
61#define REC_SPACE_NEED(buflen, reclen) do { \
62	    ssize_t _c, _l; \
63	    for (_c = 1, _l = (buflen); (_l >>= 7U) != 0; _c++) \
64		; \
65	    (reclen) = 1 + _c + (buflen); \
66	} while (0)
67
68 /*
69  * Stuff that needs <stdarg.h>
70  */
71extern int rec_vfprintf(VSTREAM *, int, const char *, va_list);
72
73/* LICENSE
74/* .ad
75/* .fi
76/*	The Secure Mailer license must be distributed with this software.
77/* AUTHOR(S)
78/*	Wietse Venema
79/*	IBM T.J. Watson Research
80/*	P.O. Box 704
81/*	Yorktown Heights, NY 10598, USA
82/*--*/
83
84#endif
85