'\"macro stdmacro
.if n .pH g3e.elf_error @(#)elf_error	40.9 of 10/27/89
.\" Copyright 1989 AT&T
.\"#ident	"@(#)ci5-doc:req/libelf/error.man	1.3"
.nr X
.if \nX=0 .ds x} elf_error 3E "ELF Library" "\&"
.if \nX=1 .ds x} elf_error 3E "ELF Library"
.if \nX=2 .ds x} elf_error 3E "" "\&"
.if \nX=3 .ds x} elf_error "" "" "\&"
.TH \*(x}
.SH NAME
\f4elf_errmsg\f1, \f4elf_errno\f1 \- error handling
.SH SYNOPSIS
\f4cc\f1
[\f2flag\fP \|.\|.\|.] \f2file\fP \|.\|.\|.
\f4\-lelf\f1
[\f2library\fP \|.\|.\|.]
.PP
.nf
\f4#include <libelf.h>\f1
.sp 0.5
\f4const char \(**elf_errmsg(int err);\f1
\f4int elf_errno(void);\f1
.fi
.SH DESCRIPTION
If an
.SM ELF
library function fails, a program
may call
\f4elf_errno\fP
to retrieve the library's internal error number.
As a side effect, this function resets the
internal error number to zero, which indicates no error.
.P
\f4elf_errmsg\fP
takes an error number,
.IR err ,
and returns a null-terminated error message (with no trailing new-line)
that describes the problem.
A zero
.I err
retrieves a message for the most recent error.
If no error has occurred, the return value is a null pointer
(not a pointer to the null string).
Using
.I err
of \-1 also retrieves the most recent error, except it
guarantees a non-null return value, even when no error has occurred.
If no message is available for the given number,
\f4elf_errmsg\fP
returns a pointer to an appropriate message.
This function does not have the side effect of
clearing the internal error number.
.SH EXAMPLE
The following fragment clears the internal error number
and checks it later for errors.
Unless an error occurs after the first call to
\f4elf_errno\fP,
the next call will return zero.
.P
.RS .5i
.DT
.nf
.ft 4
.ta 8u*\w' 'u +8u*\w' 'u +8u*\w' 'u +8u*\w' 'u +8u*\w' 'u +8u*\w' 'u
.ne 10
(void)elf_errno();
while (more_to_do)
{
	/\(** processing ... \(**/
	if ((err = elf_errno()) != 0)
	{
		msg = elf_errmsg(err);
		/\(** print msg \(**/
	}
}
.fi
.RE
.SH "SEE ALSO"
.na
\f4elf\fP(3E),
\f4elf_version\fP(3E).
