27
27
#include < sys/types.h>
28
28
#endif
29
29
30
- #ifdef __MINGW32__
30
+ #ifdef _WIN32
31
31
#include < windows.h>
32
32
/* strerror is inconsistent with errno.h numbers on MinGW32 (only?) */
33
33
const char * oserror (int error_code)
@@ -38,9 +38,6 @@ const char* oserror(int error_code)
38
38
NULL , dwError, MAKELANGID (LANG_NEUTRAL, SUBLANG_NEUTRAL), (LPTSTR)&lpMsgBuf, 0 , NULL )) {
39
39
return " (error message not available)" ;
40
40
} else {
41
- // hansbug: i didnt change this code to remove \r\n for safety
42
- // but i suggest to optimize this code, the current code can only remove \n
43
- // which will leave a \r on windows
44
41
char * eol = lpMsgBuf; // remove end of lines from M$ idiocracies:
45
42
while (NULL != (eol = strchr (eol, ' \n ' ))) {
46
43
if (eol[1 ] == 0 )
@@ -52,56 +49,14 @@ const char* oserror(int error_code)
52
49
}
53
50
}
54
51
55
- #elif _MSC_VER
56
-
57
- #include < windows.h>
58
- #include < strsafe.h>
59
-
60
- const char * oserror (int error_code)
61
- {
62
- DWORD dwError = (DWORD)error_code;
63
- LPSTR lpMsgBuf = NULL ;
64
-
65
- if (!FormatMessageA (
66
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
67
- FORMAT_MESSAGE_FROM_SYSTEM |
68
- FORMAT_MESSAGE_IGNORE_INSERTS,
69
- NULL ,
70
- dwError,
71
- MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
72
- (LPSTR)&lpMsgBuf,
73
- 0 ,
74
- NULL )) {
75
- return " (error message not available)" ;
76
- } else {
77
- size_t len = strlen (lpMsgBuf);
78
-
79
- while ((len > 0 ) && ((lpMsgBuf[len - 1 ] == ' \n ' ) || (lpMsgBuf[len - 1 ] == ' \r ' ))) {
80
- lpMsgBuf[len - 1 ] = ' \0 ' ;
81
- len -= 1 ;
82
- }
83
- int i = 0 ;
84
- for (; i < len; i++) {
85
- if ((lpMsgBuf[i] == ' \n ' ) || (lpMsgBuf[i] == ' \r ' )) {
86
- lpMsgBuf[i] = ' .' ;
87
- }
88
- }
89
-
90
- static char errorMsg[256 ];
91
- StringCchCopyA (errorMsg, sizeof (errorMsg), lpMsgBuf);
92
- LocalFree (lpMsgBuf);
93
- return errorMsg;
94
- }
95
- }
96
-
97
52
#else /* UNIX */
98
53
99
54
#include < string.h>
100
55
const char * oserror (int error_code) { return strerror (error_code); }
101
56
102
57
#endif
103
58
104
- #if defined(__MINGW32__) || defined(_MSC_VER)
59
+ #ifdef _WIN32
105
60
106
61
void base_getMemInfo (meminfo_t * info)
107
62
{
@@ -234,7 +189,7 @@ void base_getMemInfo(meminfo_t* info)
234
189
235
190
#endif
236
191
237
- #if defined(__MINGW32__) || defined(_MSC_VER)
192
+ #ifdef _WIN32
238
193
239
194
#include < psapi.h>
240
195
#include < stdint.h>
@@ -252,25 +207,11 @@ void base_getProcInfo(procinfo_t* info)
252
207
FILETIME ftExitTime;
253
208
FILETIME ftKernelTime;
254
209
FILETIME ftUserTime;
255
- #ifdef _MSC_VER
256
- PROCESS_MEMORY_COUNTERS pmc = {0 };
257
- #else
258
210
PROCESS_MEMORY_COUNTERS pmc;
259
- #endif
260
211
pmc.cb = sizeof (pmc);
261
212
262
213
GetSystemTimeAsFileTime (&now);
263
-
264
- #ifdef _MSC_VER
265
- // we have to check the return value of GetProcessMemoryInfo on MSC environment
266
- if (!GetProcessMemoryInfo (hThisProcess, &pmc, sizeof (pmc))) {
267
- memset (info, 0 , sizeof (procinfo_t ));
268
- return ;
269
- }
270
- #else
271
214
GetProcessMemoryInfo (hThisProcess, &pmc, sizeof (pmc));
272
- #endif
273
-
274
215
if (GetProcessTimes (hThisProcess, &ftCreationTime, &ftExitTime, &ftKernelTime, &ftUserTime)) {
275
216
li.LowPart = ftUserTime.dwLowDateTime ;
276
217
li.HighPart = ftUserTime.dwHighDateTime ;
0 commit comments