Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

perror - Output error message

&pagelevel(4)&pagelevel


Definition

#include <stdio.h>

void *perror(const char *s);

perror writes to the standard error output an error message corresponding to the error code in the internal C variable errno. s, a string passed as an argument, is output first, followed by a colon and the short error text from <errno.h>; the message is terminated with a newline character:

s : <short error message>\n

The following error information is provided:

  • a text which briefly describes the error,

  • the name of the function with the error, and

  • the DMS error code (hexadecimal), if any.

Notes

errno error texts may contain the appropriate DMS error codes as supplementary information, e.g. in the case of I/O errors or when system commands are executed.
You will find a list of all errno error codes and error texts in the include file <errno.h>.

If a NULL pointer is passed as argument s, only the errno error text is output.

The contents of the area in which the error code and the error text are stored are not explicitly deleted. This means that the previous contents are retained until they are overwritten with appropriate information when a fresh error occurs. Consequently, perror calls are only useful immediately after a function has provided an error return value.

With KR functionality (applies to C/C++ versions prior to V3.0 only) a value of type char * is returned. It contains a pointer to an internal C buffer with the error message. The contents are overwritten for each new call to perror.

Example

The following program opens the file fnam for reading. If the file does not exist, the following error message is printed on the standard output:

Program fopen: dataset not found (cmd: OPEN), errorcode=DD33

DD33 is the DMS error code.

#include <stdio.h>
int main(void)
{
  FILE *fp;
  if((fp = fopen("fnam", "r")) == NULL)
    perror("Program fopen");
  return 0;
}