2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
5 Desc: dos.library function Fault()
8 #include <aros/system.h>
9 #include "dos_intern.h"
15 /*****************************************************************************
18 #include <proto/dos.h>
23 AROS_LHA(LONG
, code
, D1
),
24 AROS_LHA(CONST_STRPTR
, header
, D2
),
25 AROS_LHA(STRPTR
, buffer
, D3
),
26 AROS_LHA(LONG
, len
, D4
),
29 struct DosLibrary
*, DOSBase
, 78, Dos
)
32 Fault will obtain the error message string for the given error
33 code. First the header string is copied to the buffer, followed
34 by a ":" (colon), then the NULL terminated string for the error
35 message into the buffer.
37 By convention, error messages are ALWAYS less than 80 (plus 1 for
38 NULL termination), and ideally less than 60 characters.
40 If the error code is not known, then the string "Unknown error"
41 followed by the error number will be added to the string.
44 code - The error code.
45 header - The string to prepend to the buffer before the error
46 text. This may be NULL in which case nothing is prepended.
47 buffer - The destination buffer.
48 len - Length of the buffer.
51 Number of characters placed in the buffer, may be 0.
63 *****************************************************************************/
76 /* Do this to make sure there is room for a NULL terminator */
81 while((index
< len
) && *header
)
83 buffer
[index
++] = *header
++;
86 buffer
[index
++] = ':';
87 buffer
[index
++] = ' ';
90 theString
= DosGetString(code
);
93 while((index
< len
) && *theString
)
95 buffer
[index
++] = *theString
++;
100 /* String buffer/index for long 2 string */
101 UBYTE l2str
[12], l2idx
= 11;
104 while((index
< len
) && *theString
)
106 buffer
[index
++] = *theString
++;
109 /* If the number is negative, whack in a - sign. */
113 buffer
[index
++] = '-';
116 /* Convert the number to a string, I work backwards, its easier */
117 l2str
[l2idx
--] = '\0';
120 l2str
[l2idx
--] = (code
% 10) + '0';
126 /* Copy the number onto the fault string */
127 while((index
< len
) && l2str
[l2idx
])
129 buffer
[index
++] = l2str
[l2idx
++];
132 buffer
[index
] = '\0';
133 return (len
- index
+ 1);