io: don't add a null terminator with slurp
This commit is contained in:
parent
ab330cc520
commit
ecb97143cf
6
io.cpp
6
io.cpp
@ -47,10 +47,8 @@ util::slurp (const boost::filesystem::path& path) {
|
|||||||
if (lseek (out, 0, SEEK_SET) == (off_t)-1)
|
if (lseek (out, 0, SEEK_SET) == (off_t)-1)
|
||||||
throw errno_error ();
|
throw errno_error ();
|
||||||
|
|
||||||
// Allocate a buffer, and keep reading until it's full. We provide a null
|
// Allocate a buffer, and keep reading until it's full.
|
||||||
// padding at the tail as a 'just in case' measure for string manipulation.
|
std::vector<char> buffer (size);
|
||||||
std::vector<char> buffer (size + 1);
|
|
||||||
buffer.data ()[size] = '\0';
|
|
||||||
|
|
||||||
CHECK_GE (size, 0);
|
CHECK_GE (size, 0);
|
||||||
size_t remaining = (size_t)size;
|
size_t remaining = (size_t)size;
|
||||||
|
4
io.hpp
4
io.hpp
@ -67,10 +67,8 @@ namespace util {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/// Reads an entire file into memory. Caller frees the result. Guarantees a
|
/// Reads an entire file into memory.
|
||||||
/// null trailing byte.
|
|
||||||
std::vector<char> slurp (const boost::filesystem::path&);
|
std::vector<char> slurp (const boost::filesystem::path&);
|
||||||
|
|
||||||
std::vector<char> slurp (FILE *);
|
std::vector<char> slurp (FILE *);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user