Category : C Source Code
Archive   : CRERR4G.ZIP
Filename : CRITERR.C

Output of file : CRITERR.C contained in archive : CRERR4G.ZIP

#define IGNORE 0
#define RETRY 1
#define ABORT 2
#define FAIL 3

typedef unsigned int DWORD;

char *critical_errors[] =
"write-protect error",
"unknown unit",
"drive not ready",
"unknown command",
"data error (bad CRC)",
"bad request structure length",
"seek error",
"unknown media type",
"sector not found",
"printer out of paper",
"write fault",
"read fault",
"general failure"

int criterr_flag;

/* This argument list sets up the registers saved by the __interrupt
keyword as arguments to the handler. We need access to the saved
EAX value, because we need to return a value from the handler to
tell DOS what to do, but we will restore all registers upon return.
Note that this function must be compiled with stack calling
conventions in order to allow accessing the registers this way,
and we must declare EAX as a volatile to prevent the compiler
from optimizing out our attempt to set it.

#pragma aux ehandler parm [];
void __interrupt ehandler (DWORD rgs, DWORD rfs, DWORD res, DWORD rds,
DWORD redi, DWORD resi, DWORD rebp, DWORD resp,
DWORD rebx, DWORD redx, DWORD recx,
DWORD volatile reax)
int c;

criterr_flag = 1;
cputs ("Unexpected error: ");
c = redi & 0xff;
cputs (c >= (sizeof(critical_errors)/sizeof(char *)) ?
"unknown type" : critical_errors[c]);
cputs ("\r\nAbort, Retry, Ignore, Fail? ");

if (! (c = getch ()))
getch (); /* Accept (but ignore) extended key codes */
c = toupper (c);

if (c == 'A')
reax = ABORT;
else if (c == 'F')
reax = FAIL;
else if (c == 'I')
reax = IGNORE;
else if (c == 'R')
reax = RETRY;
goto prompt; /* Repeat until satisfied */
cputs ("\r\n");

void main (void)
FILE *fp;
union REGPACK r;
void _far *h = (void _far *) ehandler; = 0x2524; /* Set critical error vector */
r.x.edx = FP_OFF(h); /* Vector is in DS:EDX */
r.x.ds = FP_SEG(h); = r.x.fs = = 0;
intr (0x21, &r); /* DOS services */

criterr_flag = 0;

fp = fopen ("b:foo", "r");

if (criterr_flag)
puts ("Critical error detected opening B:FOO.");

if (fp)
fclose (fp);
puts ("Failed to open file.");

  3 Responses to “Category : C Source Code
Archive   : CRERR4G.ZIP
Filename : CRITERR.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: