Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I see the list of functions that interact with 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 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?

like image 512
Ori Popowski Avatar asked Jul 12 '09 18:07

Ori Popowski


People also ask

How do you check errno?

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.

What library is errno in?

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

Where is errno stored?

It's probably allocated, as in actual storage, in the thread stack header.

Does Read set errno?

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.


1 Answers

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.

like image 92
Michael Burr Avatar answered Sep 29 '22 14:09

Michael Burr