繁体   English   中英

Zlib 调用 gzopen 和 gzclose 后返回错误代码 2

[英]Zlib returns error code 2 after calling gzopen and gzclose

我有一个类似于下面代码的压缩函数。 它基本上从我的应用程序中获取日志文件并使用Zlib压缩它们。 一位用户报告了这样的错误: Failed compressing file: 'C:/ProgramData/AppName/logs/cef.log'; error number 2. 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)};

(...)

那不是 zlib 错误代码。 这是一个stdio errno代码。 2表示未找到文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM