Function Name: Harderr
Function: Create a hardware error handler
Usage: void harderr (int (*fptr) ());
program Example:
/*this program would trap disk errors and prompt
The user for action. Try running it with no
Disk in drive a:to invoke its functions.*/
#include
#include
#include
#define IGNORE 0
#define RETRY 1
#define ABORT 2
int buf[500];
/*define the error messages for trapping disk problems*/
static char *err_msg[] = {
"Write Protect",
"Unknown Unit",
"Drive not Ready",
"Unknown Command",
"Data error (CRC)",
"Bad Request",
"Seek Error",
"Unknown media type",
"Sector not Found",
"Printer out of paper",
"Write Fault",
"Read Fault,"
"General Failure",
"Reserved",
"Reserved",
"Invalid disk Change"
};
Error_win (char *msg)
{
int retval;
Cputs (msg);
/*prompt for user to press a key to abort, retry, ignore*/
while (1)
{
Retval= Getch ();
if (retval = = ' a ' | | retval = = ' A ')
{
retval = ABORT;
Break
}
if (retval = = ' R ' | | retval = = ' R ')
{
retval = retry;
Break
}
if (retval = = ' I ' | | retval = = ' I ')
{
retval = IGNORE;
Break
}
}
return (retval);
}
/*pragma Warn-par reduces warnings which occur
Due to the non use of the parameters Errval,
BP and Si to the handler.*/
#pragma warn-par
int handler (int errval,int ax,int bp,int si)
{
static Char msg[80];
unsigned di;
int drive;
int Errorno;
Di= _di;
/*if This isn't a disk error then it was
Another device having trouble*/
if (Ax < 0)
{
* The error * *
Error_win ("Device error");
/* and return to the program directly requesting abort * *
HARDRETN (ABORT);
}
/* Otherwise it was a disk error */
Drive = ax & 0x00ff;
Errorno = di & 0x00ff;
/* The which error it was * *
sprintf (MSG, "Error:%s on drive%c\r\na) bort, R) etry, I) Gnore:",
Err_msg[errorno], ' A ' + drive);
/*
Return to the program via DOS interrupt 0x23 with abort, retry,
or ignore as input by the user.
*/
Hardresume (Error_win (msg));
return ABORT;
}
#pragma warn +par
int main (void)
{
/*
Install our handler on the hardware problem interrupt
*/
Harderr (handler);
CLRSCR ();
printf ("Make sure there are no disk in drive a:\n");
printf ("Press any key ... \ n");
Getch ();
printf ("Trying to access drive a:\n");
printf ("Fopen returned%p\n", fopen ("A:temp.dat", "w"));
return 0;
}