io: add slurp for uint32_t
This commit is contained in:
parent
497d3ca970
commit
c51673e421
7
io.cpp
7
io.cpp
@ -38,14 +38,12 @@ template <typename T>
|
|||||||
std::vector<T>
|
std::vector<T>
|
||||||
util::slurp (const std::experimental::filesystem::path &path)
|
util::slurp (const std::experimental::filesystem::path &path)
|
||||||
{
|
{
|
||||||
static_assert (
|
|
||||||
sizeof (T) == 1,
|
|
||||||
"slurp is designed for grabbing bytes, not complex structures"
|
|
||||||
);
|
|
||||||
posix::fd out (path, O_RDONLY | O_BINARY);
|
posix::fd out (path, O_RDONLY | O_BINARY);
|
||||||
|
|
||||||
// Calculate the total file size
|
// Calculate the total file size
|
||||||
off_t size = posix::error::try_value (lseek (out, 0, SEEK_END));
|
off_t size = posix::error::try_value (lseek (out, 0, SEEK_END));
|
||||||
|
if (size % sizeof (T))
|
||||||
|
throw std::runtime_error ("filesize not correctly rounded");
|
||||||
|
|
||||||
posix::error::try_value (lseek (out, 0, SEEK_SET));
|
posix::error::try_value (lseek (out, 0, SEEK_SET));
|
||||||
|
|
||||||
@ -75,6 +73,7 @@ util::slurp (const std::experimental::filesystem::path &path)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template std::vector<char> util::slurp (const std::experimental::filesystem::path&);
|
template std::vector<char> util::slurp (const std::experimental::filesystem::path&);
|
||||||
template std::vector<std::byte> util::slurp (const std::experimental::filesystem::path&);
|
template std::vector<std::byte> util::slurp (const std::experimental::filesystem::path&);
|
||||||
|
template std::vector<uint32_t> util::slurp (const std::experimental::filesystem::path&);
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
x
Reference in New Issue
Block a user