gtpc2m5c | C/C++ Language Support User's Guide |
This function prints an error message to stderr.
Format
#include <stdio.h> void perror(const char *string);
If string is not NULL and it does not point to a null character, the string pointed to by string is printed to the standard error stream followed by a colon and a space. The message associated with the value in errnois then printed, followed by a new-line character. The content of the message is the same as the content of a string returned by the strerror function when passed the value of errno.
To produce accurate results, ensure that the perrorfunction is called immediately after a library function returns with an error; otherwise, subsequent calls may change the errno value.
If the error is associated with the stderr file, a call to perror is not valid.
TARGET(TPF) restriction |
---|
Avoid the TARGET(TPF) implementation of the perrorfunction because it is nonstandard. It requires the application to set errno to a system error number and cause a system error with return using the string parameter as the appended console message. Instead of perror in TARGET(TPF), use the snapc function or one of the serrc_op family of functions. |
Normal Return
Returns no value.
Error Return
Not applicable.
Programming Considerations
The TPF system does not support creating, updating, or deleting files in 1052 or UTIL state. Special files may or may not be writable in 1052 or UTIL state depending on the device driver implementation.
Examples
The following example tries to open a stream. If the fopen function fails, the example prints a message and ends the program.
#include <stdio.h> #include <stdlib.h> int main(void) { FILE *fh; if ((fh = fopen("myfile.dat","r")) == NULL) { perror("Could not open data file"); abort(); } }
Related Information