mirror of
https://github.com/SFML/SFML.git
synced 2025-01-31 13:45:13 +08:00
Ensure consistent behavior between Android and other OSes
Android never checked if m_file was null and thus would invoke UB upon calling certain functions whereas all other OSes would return a defined value.
This commit is contained in:
parent
9b751899eb
commit
fe0785769e
@ -80,13 +80,12 @@ bool FileInputStream::open(const std::filesystem::path& filename)
|
||||
////////////////////////////////////////////////////////////
|
||||
std::int64_t FileInputStream::read(void* data, std::int64_t size)
|
||||
{
|
||||
if (!m_file)
|
||||
return -1;
|
||||
#ifdef SFML_SYSTEM_ANDROID
|
||||
return m_file->read(data, size);
|
||||
#else
|
||||
if (m_file)
|
||||
return static_cast<std::int64_t>(std::fread(data, 1, static_cast<std::size_t>(size), m_file.get()));
|
||||
else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -94,20 +93,15 @@ std::int64_t FileInputStream::read(void* data, std::int64_t size)
|
||||
////////////////////////////////////////////////////////////
|
||||
std::int64_t FileInputStream::seek(std::int64_t position)
|
||||
{
|
||||
if (!m_file)
|
||||
return -1;
|
||||
#ifdef SFML_SYSTEM_ANDROID
|
||||
return m_file->seek(position);
|
||||
#else
|
||||
if (m_file)
|
||||
{
|
||||
if (std::fseek(m_file.get(), static_cast<long>(position), SEEK_SET))
|
||||
return -1;
|
||||
|
||||
return tell();
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -115,13 +109,12 @@ std::int64_t FileInputStream::seek(std::int64_t position)
|
||||
////////////////////////////////////////////////////////////
|
||||
std::int64_t FileInputStream::tell()
|
||||
{
|
||||
if (!m_file)
|
||||
return -1;
|
||||
#ifdef SFML_SYSTEM_ANDROID
|
||||
return m_file->tell();
|
||||
#else
|
||||
if (m_file)
|
||||
return std::ftell(m_file.get());
|
||||
else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -129,11 +122,11 @@ std::int64_t FileInputStream::tell()
|
||||
////////////////////////////////////////////////////////////
|
||||
std::int64_t FileInputStream::getSize()
|
||||
{
|
||||
if (!m_file)
|
||||
return -1;
|
||||
#ifdef SFML_SYSTEM_ANDROID
|
||||
return m_file->getSize();
|
||||
#else
|
||||
if (m_file)
|
||||
{
|
||||
const std::int64_t position = tell();
|
||||
std::fseek(m_file.get(), 0, SEEK_END);
|
||||
const std::int64_t size = tell();
|
||||
@ -142,11 +135,6 @@ std::int64_t FileInputStream::getSize()
|
||||
return -1;
|
||||
|
||||
return size;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user