blob: ec8c7dd41c06a7d3a1128ce133db8a72b1ee3da3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
/***
*strerror.c - Contains the strerror C runtime.
*
* Copyright (c) 1987-1993, Microsoft Corporation. All rights reserved.
*
*Purpose:
* The strerror runtime accepts an error number as input
* and returns the corresponding error string.
*
* NOTE: The "old" strerror C runtime resides in file _strerr.c
* and is now called _strerror. The new strerror runtime
* conforms to the ANSI standard.
*
*Revision History:
* 02-24-87 JCR Module created.
* 12-11-87 JCR Added "_LOAD_DS" to declaration
* 01-04-87 JCR Improved code.
* 01-05-87 JCR Multi-thread support
* 05-31-88 PHG Merge DLL and normal versions
* 06-06-89 JCR 386 mthread support
* 03-16-90 GJF Replaced _LOAD_DS with _CALLTYPE1, added #include
* <cruntime.h> and fixed the copyright. Also, cleaned
* up the formatting a bit.
* 10-04-90 GJF New-style function declarator.
* 07-18-91 GJF Multi-thread support for Win32 [_WIN32_].
* 02-17-93 GJF Changed for new _getptd().
*
*******************************************************************************/
#include <cruntime.h>
#include <errmsg.h>
#include <stdlib.h>
#include <syserr.h>
#include <string.h>
#include <os2dll.h>
#ifdef MTHREAD
#include <malloc.h>
#include <stddef.h>
#endif
/* [NOTE: The mthread error message buffer is shared by both strerror
and _strerror so must be the max length of both. */
#ifdef MTHREAD
/* Max length of message = user_string(94)+system_string+2 */
#define _ERRMSGLEN_ 94+_SYS_MSGMAX+2
#else
/* Max length of message = system_string+2 */
#define _ERRMSGLEN_ _SYS_MSGMAX+2
#endif
/***
*char *strerror(errnum) - Map error number to error message string.
*
*Purpose:
* The strerror runtime takes an error number for input and
* returns the corresponding error message string. This routine
* conforms to the ANSI standard interface.
*
*Entry:
* int errnum - Integer error number (corresponding to an errno value).
*
*Exit:
* char * - Strerror returns a pointer to the error message string.
* This string is internal to the strerror routine (i.e., not supplied
* by the user).
*
*Exceptions:
* None.
*
*******************************************************************************/
char * _CRTAPI1 strerror (
int errnum
)
{
#ifdef MTHREAD
#ifdef _CRUISER_
struct _tiddata * tdata;
#else /* ndef _CRUISER_ */
#ifdef _WIN32_
_ptiddata ptd = _getptd();
#else /* ndef _WIN32_ */
#error ERROR - ONLY CRUISER OR WIN32 TARGET SUPPORTED!
#endif /* _WIN32_ */
#endif /* _CRUISER_ */
char *errmsg;
static char errmsg_backup[_SYS_MSGMAX+2];
#else
static char errmsg[_ERRMSGLEN_]; /* Longest errmsg + \0 */
#endif
#ifdef MTHREAD
#ifdef _CRUISER_
tdata = _gettidtab(); /* get tid's data address */
if (tdata->_errmsg == NULL) {
if ( (tdata->_errmsg = malloc(_ERRMSGLEN_)) == NULL)
errmsg = errmsg_backup; /* error: use backup */
else
errmsg = tdata->_errmsg;
}
else
errmsg = tdata->_errmsg;
#else /* ndef _CRUISER_ */
#ifdef _WIN32_
if ( (ptd->_errmsg == NULL) && ((ptd->_errmsg = malloc(_ERRMSGLEN_))
== NULL) )
errmsg = errmsg_backup; /* error: use backup */
else
errmsg = ptd->_errmsg;
#else /* ndef _WIN32_ */
#error ERROR - ONLY CRUISER OR WIN32 TARGET SUPPORTED!
#endif /* _WIN32_ */
#endif /* _CRUISER_ */
#endif
strcpy(errmsg, _sys_err_msg(errnum));
return(errmsg);
}
|