Why does perror function return success value?
11,588
Take a look at the man page below. http://man7.org/linux/man-pages/man3/perror.3.html
The first two paragraphs have the content you need.
Essentially the string representation of "errno" a global variable is printed out along with your arguments. If you have no errors (errono = 0). This is causing your program to print "SUCCESS".
Related videos on Youtube
Author by
Tomer Aronovsky
Updated on June 04, 2022Comments
-
Tomer Aronovsky almost 2 years
i write a code for tcp connection in c language, and in some place i added two perrors:
perror("FAIL1: ..."); perror("FAIL2: ...");
and the output is: FAIL1: ..: Success FAIL2: ..: Invalid argument Just want to understand - what does it mean the "Success"? TNX!
-
James T. Smith about 9 yearsIt means the
errno
variable contains no error code. perror() reads the value oferrno
and prints a corresponding message to stderr. -
James T. Smith about 9 yearsAs an example: You can change the error code to something like EACCES and then call perror() to see what is printed.
-
kaylum about 9 yearsI think you mean
errno
. -
that other guy about 9 years"Success" means there was no error. If your question actually is "A function's return code indicates failure but perror says success", it you made additional syscalls between the failure and the perror that happened to succeed.
-