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

Share:
11,588

Related videos on Youtube

Tomer Aronovsky
Author by

Tomer Aronovsky

Updated on June 04, 2022

Comments

  • Tomer Aronovsky
    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
      James T. Smith about 9 years
      It means the errno variable contains no error code. perror() reads the value of errno and prints a corresponding message to stderr.
    • James T. Smith
      James T. Smith about 9 years
      As an example: You can change the error code to something like EACCES and then call perror() to see what is printed.
    • kaylum
      kaylum about 9 years
      I think you mean errno.
    • that other guy
      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.