nih-at/libzip

errno: default is not 0

1397436824 opened this issue · 10 comments

Describe the Bug
[A clear and concise description of what the bug is.](errno: default is not 0)

Expected Behavior
default errno = 2

There is not enough information here.
errno is suppopsed to be set by the operating system when an error occurs, not by an application library.

The following example will illustrate the issue of errno being libzip:
image

这里没有足够的信息。 errno 应该由操作系统在发生错误时设置,而不是由应用程序库设置。

As long as compile with - lzip, errno will be set to 2

Please read up on errno some more - at the point where you are checking it, the value of errno is undefined.

Please read up on errno some more - at the point where you are checking it, the value of errno is undefined.

Obviously, it's a problem with libzip. I've never seen a reference to another library where errno is not zero. If you can find another library that references errno that is not zero, then I believe you.
image

Please read up on errno some more - at the point where you are checking it, the value of errno is undefined.

Obviously, it's a problem with libzip. I've never seen a reference to another library where errno is not zero. If you can find another library that references errno that is not zero, then I believe you. image

I am working on a large project, using dozens of libraries and debugging for a long time. I found this issue with libzip

dillof commented

libcurses also sets errno to non-zero during it's initialisation.

But all that is besides the point: according to the standard, the value of errno is undefined unless an error occurred. That means, you can't rely on it's value, even if it happens to be 0 on your system; it might not be on other systems.

libcurses 还在初始化期间将 errno 设置为非零。

但这一切都不是重点:根据标准,除非发生错误,否则errno 的值是_未定义的。_这意味着,您不能依赖它的价值,即使它恰好0在您的系统上;它可能不在其他系统上。

Okay, but it's still recommended to set up errno and standardize it just like the Linux system library

dillof commented

No, for a library, it's recommended to leave errno alone unless you explicitly set it in case of an error.

If you want it to be 0 at a specific point in your program, set it yourself exactly there.

dillof commented

Also, have you tested if it is set by any of the library libzip links against and not by libzip itself? (zlib, lzma, bz2, …)