The argument string s is printed first, then a colon and a blank, then the message and a new-line. To be of most use, the argument string should include the name of the function that incurred the error. The error number is taken from the external variable errno , which is set when errors occur but not cleared when non-erroneous calls are made. When a system call fails, it usually returns -1 and sets the variable errno to a value describing what went wrong.
Many library functions do likewise.
Thus, if a failing call is not immediately followed by a call to perror , the value of errno should be saved.