[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1


elf_errmsg, elf_errno Subroutine

Purpose

Error handling

Library

cc [flag...] file... -lelf [library]...
#include <libelf.h>

Syntax


const char *elf_errmsg(int err);
int elf_errno(void);

Description

If an ELF library function fails, a program may call elf_errno 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.

Parameters


err     specifies the error number to elf_errmsg for which a null-terminated error message (with no trailing new-line) should be returned. If err is set to zero the most recent error message is returned.

Return Values

If no error has occurred, the return value is a null pointer (not a pointer to the null string). Using 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, elf_errmsg returns a pointer to an appropriate message. This function does not have the side effect of clearing the internal error number.

Examples

The following code fragment clears the internal error number and checks it later for errors. Providing no error occurs after the first call to elf_errno, the next call will return zero.

   (void)elf_errno();
   while (more_to_do)
   {
          /* processing ... */
          if ((err = elf_errno()) != 0)
          {
                  msg = elf_errmsg(err);
                  /* print msg */
          }
   }

Related Information

The elf_version (elf_version Subroutine) subroutine.

Introduction to ELF Subroutines.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]