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

喜你入骨 提交于 2019-12-03 12:44:02

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.

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

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

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

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

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

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