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?
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
to0
- 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 oferrno
on entry and then set it to zero, as long as the original value is restored iferrno
'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.
来源:https://stackoverflow.com/questions/1116602/where-can-i-see-the-list-of-functions-that-interact-with-errno