Use std::span for MovieFileRead

This commit is contained in:
Kp 2023-05-06 19:26:19 +00:00
parent 53a9ce8823
commit 1053cb532b
3 changed files with 9 additions and 8 deletions

View file

@ -318,7 +318,7 @@ static int _mvefile_read_header(const MVEFILE *movie)
return 0;
/* check the file is long enough */
if (!MovieFileRead(movie->stream.get(), buffer, 26))
if (!MovieFileRead(movie->stream.get(), buffer))
return 0;
/* check the signature */
@ -359,19 +359,18 @@ static int _mvefile_fetch_next_chunk(MVEFILE *movie)
return 0;
/* fail if we can't read the next segment descriptor */
if (!MovieFileRead(movie->stream.get(), buffer, 4))
if (!MovieFileRead(movie->stream.get(), buffer))
return 0;
/* pull out the next length */
length = _mve_get_short(buffer);
/* make sure we've got sufficient space */
_mvefile_set_buffer_size(movie, length);
movie->cur_chunk.resize(length);
/* read the chunk */
if (!MovieFileRead(movie->stream.get(), &movie->cur_chunk[0], length))
if (!MovieFileRead(movie->stream.get(), movie->cur_chunk))
return 0;
movie->cur_chunk.resize(length);
movie->next_segment = 0;
return 1;

View file

@ -13,6 +13,7 @@
#include "libmve.h"
#include <cstdint>
#include <span>
#include <vector>
#include "dxxsconf.h"
#include <SDL.h>
@ -142,4 +143,4 @@ void mve_reset(MVESTREAM *movie);
*/
int mve_play_next_chunk(MVESTREAM &movie);
unsigned int MovieFileRead(SDL_RWops *handle, void *buf, unsigned count);
unsigned MovieFileRead(SDL_RWops *handle, std::span<uint8_t> buf);

View file

@ -116,9 +116,10 @@ struct movie_pause_window : window
}
unsigned int MovieFileRead(SDL_RWops *const handle, void *buf, unsigned int count)
unsigned MovieFileRead(SDL_RWops *const handle, const std::span<uint8_t> buf)
{
const unsigned numread = SDL_RWread(handle, buf, 1, count);
const auto count = buf.size();
const auto numread = SDL_RWread(handle, buf.data(), 1, count);
return (numread == count);
}