The Bottom Layer Read Function
     int <read function>(qpstream, bufptr, sizeptr)
            QP_stream        *qpstream;
            unsigned char   **bufptr;
            size_t           *sizeptr;
     Return Values:   QP_FULL  : a complete record is read
                      QP_PART  : a partial  record is read
                      QP_EOF   : end of file is reached
                      QP_ERROR : a partial  record is read

The bottom layer read function returns a record of input to its caller. The returned record is buffered. The buffer address is returned through *bufptr parameter and the size of the returned record is stored in *sizeptr parameter. The magic field in qpstream should be updated to the system-dependent file address (see fli-ios-sst-sda) for the beginning of the returned 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.

In our example, the read function does not return QP_PART since any length of input is chosen as a complete record.

     static int
     bin_read(qpstream, bufptr, sizeptr)
         QP_stream            *qpstream;
         unsigned char       **bufptr;
         size_t               *sizeptr;
             int n;
             register BinStream *stream = CoerceBinStream(qpstream);
             qpstream->magic.byteno += stream->last_rdsize;
             stream->last_rdsize = 0;
             n = read(stream->fd, (char*) stream->buffer,
                                  (int) qpstream->max_reclen);
             if (n > 0) {
                 *bufptr  = stream->buffer;
                 *sizeptr = n;
                 stream->last_rdsize = n;
                 return QP_FULL;
             } else if (n == 0) {
                 *sizeptr = 0;
                 return QP_EOF;
             } else {
                 qpstream->errno = errno;
                 return QP_ERROR;