Failed System Calls (cont)
Another library function to make it easy to report errors and exit
-
error( Status, ErrNum, Format, Expressions, ...)
- print error message using prog name, Format and Expressions
- if Status is non-zero, invoke
exit( Status) after printing message
- if ErrNum is non-zero, also print standard system error message
Example:
error(1, errno, "Can't do %s", Something);
perror("Can't do it");
exit(1);
fprintf(stderr, "Can't do %s", Something);
exit(1);
|
|