1 #include <stdio.h>
2 #include <string.h>
3 #include "libami.h"
4 
5 #ifndef AMIGAOS
6 
7 static int amiga_errno=0;
8 
9 #define MIN_ERRNO 103
10 
11 static const char *syserrmsg[] = {
12   "not enough memory available", /* 103 */
13   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
14   "bad template", /* 114 */
15   "bad number", /* 115 */
16   "required argument missing", /* 116 */
17   "value after keyword missing", /* 117 */
18   "wrong number of arguments", /* 118 */
19   NULL,
20   "argument line invalid or too long" /* 120 */
21 };
22 
Fault(LONG code,UBYTE * header,UBYTE * buffer,LONG len)23 BOOL Fault(LONG code, UBYTE *header, UBYTE *buffer, LONG len)
24 {
25   amiga_errno=code;
26   if(header) {
27     int hdlen=strlen((char *)header);
28     if(hdlen+2>len)
29       return FALSE;
30     strcpy((char *)buffer, (char *)header);
31     buffer+=hdlen;
32     *buffer++=':';
33     *buffer++=' ';
34     len-=hdlen+2;
35   }
36   if(code>=MIN_ERRNO && code<MIN_ERRNO+sizeof(syserrmsg)/sizeof(syserrmsg[0])
37      && syserrmsg[code-MIN_ERRNO]) {
38     if(len<strlen(syserrmsg[code-MIN_ERRNO])+1)
39       return FALSE;
40     strcpy((char *)buffer, syserrmsg[code-MIN_ERRNO]);
41   } else {
42     char number[6+4*sizeof(LONG)];
43     sprintf(number, "Error %ld", code);
44     if(len<strlen(number)+1)
45       return FALSE;
46     strcpy((char *)buffer, number);
47   }
48   return TRUE;
49 }
50 
PrintFault(LONG code,UBYTE * header)51 BOOL PrintFault(LONG code, UBYTE *header)
52 {
53   UBYTE buf[128];
54   if(Fault(code, header, buf, sizeof(buf))) {
55     fprintf(stderr, "%s\n", (char *)buf);
56     return TRUE;
57   } else return FALSE;
58 }
59 
IoErr()60 LONG IoErr()
61 {
62   return amiga_errno;
63 }
64 
SetIoErr(LONG code)65 LONG SetIoErr(LONG code)
66 {
67   LONG old_errno=amiga_errno;
68   amiga_errno=code;
69   return old_errno;
70 }
71 
72 #endif
73