home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / libdwarf / pro_error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  1.6 KB  |  68 lines

  1. /*
  2.  
  3.     pro_error.c
  4.  
  5.  
  6.  
  7.     $Revision: 1.1 $ $Date: 1993/07/19 22:34:15 $
  8.  
  9. */
  10.  
  11. #include <libelf.h>
  12. #include <stdio.h>
  13. #include <sys/stat.h>
  14. #include <sys/types.h>
  15. #include <stdlib.h>
  16. #include "pro_incl.h"
  17.  
  18. extern char* _dwarf_errmsgs[];
  19.  
  20. /* 
  21.     This function performs error handling as described in the 
  22.     libdwarf consumer document section 3.  Dbg is the Dwarf_P_debug
  23.     structure being processed.  Error is a pointer to the pointer
  24.     to the error descriptor that will be returned.  Errval is an
  25.     error code listed in dwarf_error.h.
  26. */
  27. void
  28. _dwarf_p_error (
  29.     Dwarf_P_Debug         dbg,
  30.     Dwarf_Error         *error,
  31.     Dwarf_Word          errval
  32. )
  33. {
  34.     Dwarf_Error     errptr;
  35.  
  36.     /* Allow NULL dbg on entry, since sometimes that can happen and
  37.        we want to report the upper-level error, not this one.
  38.     */
  39.     if ((Dwarf_Sword)errval < 0)
  40.     printf("ERROR VALUE: %d - %s\n",errval, _dwarf_errmsgs[-errval-1]);
  41.     if (error != NULL) {
  42.         errptr = (Dwarf_Error)
  43.         _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_Error_s));
  44.         if (errptr == NULL) {
  45.             fprintf(stderr,"Could not allocate Dwarf_Error structure\n");
  46.             abort();
  47.         }
  48.         errptr->er_errval = errval;
  49.         *error = errptr;
  50.         return;
  51.     }
  52.  
  53.     if (dbg != NULL && dbg->de_errhand != NULL) {
  54.         errptr = (Dwarf_Error)
  55.         _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_Error_s));
  56.         if (errptr == NULL) {
  57.             fprintf(stderr,"Could not allocate Dwarf_Error structure\n");
  58.             abort();
  59.         }
  60.         errptr->er_errval = errval;
  61.         dbg->de_errhand(errptr,dbg->de_errarg);
  62.         return;
  63.     }
  64.  
  65.     abort();
  66. }
  67.  
  68.