int <write function>(qpstream, bufptr, sizeptr)
QP_stream *qpstream;
unsigned char **bufptr;
size_t *sizeptr;
Return Values: QP_SUCCESS
QP_ERROR
The bottom layer write function writes out a record from buffer address
stored in *bufptr and the size of the record stored in *sizeptr.
Upon successful return, *sizeptr stores the maximum record size
and *bufptr stores the address of the beginning of the
buffer for the next output record. The magic field
in qpstream should be updated to the system-dependent file address
(see fli-ios-sst-sda)
for the beginning of the next output record. If there is no
seek permission for the stream, the magic field may be ignored.
The errno field in QP_stream stores the error code
if an error is detected in the function and QP_ERROR is returned.
The output record passed into the write function may be a partial record
if output record overflows the output buffer for a stream
that permits overflow.
static int
bin_write(qpstream, bufptr, sizeptr)
QP_stream *qpstream;
unsigned char **bufptr;
size_t *sizeptr;
{
BinStream *stream = CoerceBinStream(qpstream);
int n, len=(int) *sizeptr;
char *buf = (char *) *bufptr;
while ((n = write(stream->fd, buf, len)) > 0 && n < len) {
buf += n;
len -= n;
}
if (n >= 0) {
qpstream->magic.byteno += *sizeptr;
*sizeptr = qpstream->max_reclen;
*bufptr = stream->buffer;
return QP_SUCCESS;
} else {
qpstream->errno = errno;
return QP_ERROR;
}
}