mirror of
https://github.com/fmang/opustags.git
synced 2025-02-15 03:29:01 +01:00
Compare commits
No commits in common. "a54bac8f55365be24a0804cbb1294bbe744fb791" and "d9b051210ba756d28086c9b75e983e84ae11e730" have entirely different histories.
a54bac8f55
...
d9b051210b
@ -119,16 +119,13 @@ using byte_string_view = std::basic_string_view<uint8_t>;
|
||||
* \{
|
||||
*/
|
||||
|
||||
/** fclose wrapper for std::unique_ptr’s deleter. */
|
||||
void close_file(FILE*);
|
||||
|
||||
/**
|
||||
* Smart auto-closing FILE* handle.
|
||||
*
|
||||
* It implictly converts from an already opened FILE*.
|
||||
*/
|
||||
struct file : std::unique_ptr<FILE, decltype(&close_file)> {
|
||||
file(FILE* f = nullptr) : std::unique_ptr<FILE, decltype(&close_file)>(f, &close_file) {}
|
||||
struct file : std::unique_ptr<FILE, decltype(&fclose)> {
|
||||
file(FILE* f = nullptr) : std::unique_ptr<FILE, decltype(&fclose)>(f, &fclose) {}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -29,11 +29,6 @@ ot::byte_string_view operator""_bsv(const char* data, size_t size)
|
||||
return ot::byte_string_view(reinterpret_cast<const uint8_t*>(data), size);
|
||||
}
|
||||
|
||||
void ot::close_file(FILE* file)
|
||||
{
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
void ot::partial_file::open(const char* destination)
|
||||
{
|
||||
final_name = destination;
|
||||
@ -127,7 +122,7 @@ ot::byte_string ot::slurp_binary_file(const char* filename)
|
||||
|
||||
byte_string content;
|
||||
long file_size = get_file_size(f.get());
|
||||
if (file_size < 0) {
|
||||
if (file_size == -1) {
|
||||
// Read the input stream block by block and resize the output byte string as needed.
|
||||
uint8_t buffer[4096];
|
||||
while (!feof(f.get())) {
|
||||
@ -140,7 +135,7 @@ ot::byte_string ot::slurp_binary_file(const char* filename)
|
||||
} else {
|
||||
// Lucky! We know the file size, so let’s slurp it at once.
|
||||
content.resize(file_size);
|
||||
if (fread(content.data(), 1, file_size, f.get()) < size_t(file_size))
|
||||
if (fread(content.data(), 1, file_size, f.get()) < file_size)
|
||||
throw status { st::standard_error,
|
||||
"Could not read '"s + filename + "': " + strerror(errno) + "." };
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user