Displaying errno
Once errno has been declared in a program, there are two ways to check its
value if a routine fails. The simplest approach is to check the return value to
determine whether or not the routine failed, then print out the value of errno
and exit if it did. The following example illustrates this strategy:
#include <errno.h>
#include <fcntl.h>
mainO
{
}
int eid;
if «eid
=
open(II/dev/raw_hpib
ll
,
O_RDWR»
==
-1)
{
}
printf("Error occurred. Errno
=
%d", errno);
exit(1);
When this method is used, the program user must refer to the errno(2) entry
in the HP- UX Reference to determine what the printed value of errno means.
General-Purpose Routines
2-11