C language function Encyclopedia (h start)

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.