/*++ /* NAME /* record 3 /* SUMMARY /* simple typed record I/O /* SYNOPSIS /* #include <record.h> /* /* int rec_get(stream, buf, maxsize) /* VSTREAM *stream; /* VSTRING *buf; /* ssize_t maxsize; /* /* int rec_get_raw(stream, buf, maxsize, flags) /* VSTREAM *stream; /* VSTRING *buf; /* ssize_t maxsize; /* int flags; /* /* int rec_put(stream, type, data, len) /* VSTREAM *stream; /* int type; /* const char *data; /* ssize_t len; /* AUXILIARY FUNCTIONS /* int rec_put_type(stream, type, offset) /* VSTREAM *stream; /* int type; /* long offset; /* /* int rec_fprintf(stream, type, format, ...) /* VSTREAM *stream; /* int type; /* const char *format; /* /* int rec_fputs(stream, type, str) /* VSTREAM *stream; /* int type; /* const char *str; /* /* int REC_PUT_BUF(stream, type, buf) /* VSTREAM *stream; /* int type; /* VSTRING *buf; /* /* int rec_vfprintf(stream, type, format, ap) /* VSTREAM *stream; /* int type; /* const char *format; /* va_list ap; /* /* int rec_goto(stream, where) /* VSTREAM *stream; /* const char *where; /* /* int rec_pad(stream, type, len) /* VSTREAM *stream; /* int type; /* ssize_t len; /* /* REC_SPACE_NEED(buflen, reclen) /* ssize_t buflen; /* ssize_t reclen; /* /* REC_GET_HIDDEN_TYPE(type) /* int type; /* DESCRIPTION /* This module reads and writes typed variable-length records. /* Each record contains a 1-byte type code (0..255), a length /* (1 or more bytes) and as much data as the length specifies. /* /* rec_get_raw() retrieves a record from the named record stream /* and returns the record type. The \fImaxsize\fR argument is /* zero, or specifies a maximal acceptable record length. /* The result is REC_TYPE_EOF when the end of the file was reached, /* and REC_TYPE_ERROR in case of a bad record. The result buffer is /* null-terminated for convenience. Records may contain embedded /* null characters. The \fIflags\fR argument specifies zero or /* more of the following: /* .IP REC_FLAG_FOLLOW_PTR /* Follow PTR records, instead of exposing them to the application. /* .IP REC_FLAG_SKIP_DTXT /* Skip "deleted text" records, instead of exposing them to /* the application. /* .IP REC_FLAG_SEEK_END /* Seek to the end-of-file upon reading a REC_TYPE_END record. /* .PP /* Specify REC_FLAG_NONE to request no special processing, /* and REC_FLAG_DEFAULT for normal use. /* /* rec_get() is a wrapper around rec_get_raw() that always /* enables the REC_FLAG_FOLLOW_PTR, REC_FLAG_SKIP_DTXT /* and REC_FLAG_SEEK_END features. /* /* REC_GET_HIDDEN_TYPE() is an unsafe macro that returns /* non-zero when the specified record type is "not exposed" /* by rec_get(). /* /* rec_put() stores the specified record and returns the record /* type, or REC_TYPE_ERROR in case of problems. /* /* rec_put_type() updates the type field of the record at the /* specified file offset. The result is the new record type, /* or REC_TYPE_ERROR in case of trouble. /* /* rec_fprintf() and rec_vfprintf() format their arguments and /* write the result to the named stream. The result is the same /* as with rec_put(). /* /* rec_fputs() writes a record with as contents a copy of the /* specified string. The result is the same as with rec_put(). /* /* REC_PUT_BUF() is a wrapper for rec_put() that makes it /* easier to handle VSTRING buffers. It is an unsafe macro /* that evaluates some arguments more than once. /* /* rec_goto() takes the argument of a pointer record and moves /* the file pointer to the specified location. A zero position /* means do nothing. The result is REC_TYPE_ERROR in case of /* failure. /* /* rec_pad() writes a record that occupies the larger of (the /* specified amount) or (an implementation-defined minimum). /* /* REC_SPACE_NEED(buflen, reclen) converts the specified buffer /* length into a record length. This macro modifies its second /* argument. /* DIAGNOSTICS /* Panics: interface violations. Fatal errors: insufficient memory. /* Warnings: corrupted file. /* LICENSE /* .ad /* .fi /* The Secure Mailer license must be distributed with this software. /* AUTHOR(S) /* Wietse Venema /* IBM T.J. Watson Research /* P.O. Box 704 /* Yorktown Heights, NY 10598, USA /* /* Wietse Venema /* Google, Inc. /* 111 8th Avenue /* New York, NY 10011, USA
/*--*/