在哪里可以看到与 errno 交互的函数列表?
《C语言编程》一书中这样写道:
“当发生错误或文件结束时,库中的许多函数都会设置状态指示器。这些 可以明确地设置和测试指标。 另外,整数表达式
errno
(声明为 在中)可能包含一个错误号,该错误号提供有关最 最近的错误。”
在哪里可以看到这些函数的列表?
In the book "The C Programming Language" it says:
"Many of the functions in the library set status indicators when error or end of file occur. These
indicators may be set and tested explicitly. In addition, the integer expressionerrno
(declared
in<errno.h>
) may contain an error number that gives further information about the most
recent error."
Where can I see a list of these functions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
该标准对
errno
是这样说的:这对我来说,任何库函数都可以以任何它喜欢的方式使用
errno
,除了:errno
设置为0
请注意,该标准在脚注中建议以下内容:
正如其他答案中所述,标准之外的函数也通常会设置 errno 。
The standard says this about
errno
:Which says to me that any library function can screw around with
errno
in any way it likes except:errno
to0
Note that the standard suggests the following in a footnote:
As noted in other answers, it's common for functions that are not in the standard to set
errno
as well.您应该假设任何函数都可以设置 errno,而不仅仅是标准库中的函数。 因此,列出一份清单有点毫无意义。
You should assume that any function can set errno, not just those in the standard library. A list would therefore be a little pointless.
如果发生错误,即函数返回 -1 时,几乎所有 posix 库函数都可以设置 errno。
线程函数是一个例外,因为从多个线程设置一个全局错误变量将是非常危险的。 成功时返回 0,否则返回错误代码(此代码与 errno 兼容,因此您可以在其上使用 strerror 和 perror 函数)。
Nearly all posix library functions can set errno if an error occurs, that is when the function returns -1.
An exception are threading functions because setting one global error variable from multiple threads would be very dangerous. They return 0 on success, the errorcode otherwise (This code is compatible with errno so you can use the strerror and perror functions on it).
一个正确的问题可能是价值观是什么
errno
可以得到以及它们各自的含义。 您可以在intro(2)
中看到它们的列表。A proper question might be what are the values
errno
can get and what each of them means. You can see them listed inintro(2)
.@Adam,正如尼尔所说,任何函数都可以针对 errno.h 进行编译并设置 errno。 根据定义,不可能列出以这种方式编译以使用核心 errno 功能的所有实用程序。
也就是说,可以通过多种方式将错误报告给用户。 使用 errno 只是其中之一。
@Adam, as Neil said, any function can be compiled against errno.h and set errno. It is by definition, impossible to list all utilities that have been compiled in this way to use the core errno functionality.
That said, there are several ways that errors may be reported back to a user. Using errno is just one.
您可以使用您喜欢的编辑器和“在文件中查找...”来搜索包含
errno
关键字的文件。You can use your favorite editor and the "Find in files..." to search for files that contain the
errno
keyword.