我有一个看起来类似于下面代码的compress函数。它基本上从我的应用程序中获取日志文件,并使用Zlib
对其进行压缩。一个用户报告这样的错误:Failed compressing file: 'C:/ProgramData/AppName/logs/cef.log'; error number 2.
我真的很讨厌C,它是错误代码。有人可以指出问题的原因吗?
string contents;
if ( ! fileContents(source, contents))
throw FailedCompressionError{"Failed to get the file contents of '" + source + "'."};
gzFile targetFile{gzopen(target.c_str(), "wb")};
const auto result{gzclose(targetFile)};
if (result != Z_OK)
Logger::Error(
"Failed closing file: '{}'; error number {}; result {}.",
target,
errno,
result
);
if (targetFile == Z_NULL)
throw FailedCompressionError{
"Failed compressing file: '" + source + "'; error number " + to_string(errno) + '.'
};
const auto contentsLength{static_cast<unsigned>(strlen(contents.c_str()))};
auto result{gzwrite(targetFile, contents.c_str(), contentsLength)};
(...)
答案 0 :(得分:1)
那不是zlib错误代码。这是一个stdio errno
代码。 2
表示找不到文件。