/* EXTERR.C - extended error saving and restoring */

#include <stdlib.h>
#include <dos.h>

#define GET_EXTERR     0x59
#define SET_EXTERR     0x5d0a

#pragma pack(1)

struct   ExtErr
{
   unsigned int errax;
   unsigned int errbx;
   unsigned int errcx;
};

void  GetExtErr(struct ExtErr * ErrInfo);
void  SetExtErr(struct ExtErr * ErrInfo);

/*****
Function: GetExtErr
get extended error information
*****/
void GetExtErr(struct ExtErr * ErrInfo)
{ 
   union  REGS regs;

   if (_osmajor >= 3)   /* only for DOS 3 and above */
   {
      regs.h.ah = GET_EXTERR;
      regs.x.bx = 0;  /* must be zero */
      intdos(&regs,&regs);
      ErrInfo->errax = regs.x.ax;
      ErrInfo->errbx = regs.x.bx;
      ErrInfo->errcx = regs.x.cx;
   }
}

/*****
Function: SetExtErr
set extended error information
*****/
void SetExtErr(struct ExtErr near * ErrInfo)
{ 
   union  REGS regs;
   struct SREGS segregs;

   if (_osmajor >= 3)   /* only for DOS  3 and above */
   {
      regs.x.ax = SET_EXTERR;
      regs.x.bx = 0;       /* must be zero */
      segread(&segregs);   /* put address of err info in DS:DX */
      regs.x.dx = (int) ErrInfo;
      intdosx(&regs,&regs,&segregs);
   }
}
