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?
Viewing and Printing the Errno Value Your program can use the strerror() and perror() functions to print the value of errno. The strerror() function returns a pointer to an error message string that is associated with errno. The perror() function prints a message to stderr.
h is a header file in the standard library of the C programming language. It defines macros for reporting and retrieving error conditions using the symbol errno (short for "error number").
It's probably allocated, as in actual storage, in the thread stack header.
Upon successful completion, read(), pread() and readv() return a non-negative integer indicating the number of bytes actually read. Otherwise, the functions return -1 and set errno to indicate the error.
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:
errno
to 0
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With