X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Ffile_log.cc;h=a9522bad507dc722033074c9a5abd45c7770dcf5;hb=3f9fae119d89bf5a8dbd4dd531eb10d10c81811c;hp=5cc9c556942b4868de44a835ce305f2b0eebab12;hpb=689fa55d1529ad88449ca464e9107c4dcc54d1cb;p=dcpomatic.git diff --git a/src/lib/file_log.cc b/src/lib/file_log.cc index 5cc9c5569..a9522bad5 100644 --- a/src/lib/file_log.cc +++ b/src/lib/file_log.cc @@ -69,7 +69,11 @@ FileLog::head_and_tail (int amount) const 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(-1)) { + return ""; + } if (size < (head_amount + tail_amount)) { head_amount = size; @@ -83,23 +87,22 @@ FileLog::head_and_tail (int amount) const string out; - auto buffer = new char[max(head_amount, tail_amount) + 1]; + std::vector 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;