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