+ if (stream->pos.fd >= 0) {
+ int ret;
+
+ /*
+ * Truncate the file's size to the minimum required to fit the
+ * last packet as we might have grown it too much on the last
+ * mmap.
+ */
+ do {
+ ret = ftruncate(stream->pos.fd, stream->size);
+ } while (ret == -1 && errno == EINTR);
+ if (ret) {
+ perror("ftruncate");
+ }
+
+ if (close(stream->pos.fd)) {
+ perror("close");
+ }