int <close function>(qpstream) QP_stream *qpstream; Return Value: QP_SUCCESS QP_ERROR
The bottom layer close function performs the specific close operation of a
user-defined stream and deallocates the memory space for the stream.
It returns QP_ERROR
and assigns an appropriate error code
to the errno
field of QP_stream
if an error occurs in the function.
In our example, we use QP_free()
to deallocate memory space since the
memory is allocated by QP_malloc()
.
static int bin_close(qpstream) QP_stream *qpstream; { BinStream *stream = CoerceBinStream(qpstream); int fd = stream->fd; if (close(fd) < 0) { qpstream->errno = errno; return QP_ERROR; } (void) QP_free(qpstream); return QP_SUCCESS; }