/* Checks if the end of stream has been reached. */ MVMint64 MVM_io_syncstream_eof(MVMThreadContext *tc, MVMOSHandle *h) { MVMIOSyncStreamData *data = (MVMIOSyncStreamData *)h->body.data; /* If we still have stuff in the buffer, certainly not the end (even if * data->eof is set; that just means we read all we can from libuv, not * that we processed it all). */ if (data->ds && !MVM_string_decodestream_is_empty(tc, data->ds)) return 0; /* Otherwise, go on the EOF flag from the underlying stream. */ return data->eof; }
/* Checks if the end of file has been reached. */ static MVMint64 mvm_eof(MVMThreadContext *tc, MVMOSHandle *h) { MVMIOFileData *data = (MVMIOFileData *)h->body.data; MVMint64 seek_pos; uv_fs_t req; if (data->ds && !MVM_string_decodestream_is_empty(tc, data->ds)) return 0; if (uv_fs_fstat(tc->loop, &req, data->fd, NULL) == -1) { MVM_exception_throw_adhoc(tc, "Failed to stat file descriptor: %s", uv_strerror(req.result)); } if ((seek_pos = MVM_platform_lseek(data->fd, 0, SEEK_CUR)) == -1) MVM_exception_throw_adhoc(tc, "Failed to seek in filehandle: %d", errno); return req.statbuf.st_size == seek_pos; }
/* Checks if the end of file has been reached. */ static MVMint64 mvm_eof(MVMThreadContext *tc, MVMOSHandle *h) { MVMIOFileData *data = (MVMIOFileData *)h->body.data; MVMint64 seek_pos; uv_fs_t req; if (data->ds && !MVM_string_decodestream_is_empty(tc, data->ds)) return 0; if (uv_fs_fstat(tc->loop, &req, data->fd, NULL) == -1) { MVM_exception_throw_adhoc(tc, "Failed to stat file descriptor: %s", uv_strerror(req.result)); } if ((seek_pos = MVM_platform_lseek(data->fd, 0, SEEK_CUR)) == -1) MVM_exception_throw_adhoc(tc, "Failed to seek in filehandle: %d", errno); /* Comparison with seek_pos for some special files, like those in /proc, * which file size is 0 can be false. In that case, we fall back to check * file size to detect EOF. */ return req.statbuf.st_size == seek_pos || req.statbuf.st_size == 0; }