Where can I see the list of functions that interact with errno?

天大地大妈咪最大 提交于 2020-01-01 05:07:32

问题


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 expression errno (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?


回答1:


The standard says this about errno:

The value of errno is zero at program startup, but is never set to zero by any library function. The value of errno may be set to nonzero by a library function call whether or not there is an error, provided the use of errno is not documented in the description of the function in this International Standard.

Which says to me that any library function can screw around with errno in any way it likes except:

  • it can't set errno to 0
  • it can't do what it likes if the standard explicitly says otherwise

Note that the standard suggests the following in a footnote:

Thus, a program that uses errno for error checking should set it to zero before a library function call, then inspect it before a subsequent library function call. Of course, a library function can save the value of errno on entry and then set it to zero, as long as the original value is restored if errno's value is still zero just before the return.

As noted in other answers, it's common for functions that are not in the standard to set errno as well.




回答2:


You should assume that any function can set errno, not just those in the standard library. A list would therefore be a little pointless.




回答3:


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).




回答4:


@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.




回答5:


A proper question might be what are the values errno can get and what each of them means. You can see them listed in intro(2).




回答6:


You can use your favorite editor and the "Find in files..." to search for files that contain the errno keyword.



来源:https://stackoverflow.com/questions/1116602/where-can-i-see-the-list-of-functions-that-interact-with-errno

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!