uintmax_t head_amount = amount;
uintmax_t tail_amount = amount;
- uintmax_t size = boost::filesystem::file_size (_file);
+ boost::system::error_code ec;
+ uintmax_t size = boost::filesystem::file_size (_file, ec);
+ if (size == static_cast<uintmax_t>(-1)) {
+ return "";
+ }
if (size < (head_amount + tail_amount)) {
head_amount = size;
string out;
- auto buffer = new char[max(head_amount, tail_amount) + 1];
+ std::vector<char> buffer(max(head_amount, tail_amount) + 1);
- int N = fread (buffer, 1, head_amount, f);
+ int N = fread (buffer.data(), 1, head_amount, f);
buffer[N] = '\0';
- out += string (buffer);
+ out += string (buffer.data());
if (tail_amount > 0) {
out += "\n .\n .\n .\n";
fseek (f, - tail_amount - 1, SEEK_END);
- N = fread (buffer, 1, tail_amount, f);
+ N = fread (buffer.data(), 1, tail_amount, f);
buffer[N] = '\0';
- out += string (buffer) + "\n";
+ out += string (buffer.data()) + "\n";
}
- delete[] buffer;
fclose (f);
return out;