1 /*---------------------------------------------------------------------------*
2 * pLastError.c *
3 * *
4 * Copyright 2007, 2008 Nuance Communciations, Inc. *
5 * *
6 * Licensed under the Apache License, Version 2.0 (the 'License'); *
7 * you may not use this file except in compliance with the License. *
8 * *
9 * You may obtain a copy of the License at *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
11 * *
12 * Unless required by applicable law or agreed to in writing, software *
13 * distributed under the License is distributed on an 'AS IS' BASIS, *
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
15 * See the License for the specific language governing permissions and *
16 * limitations under the License. *
17 * *
18 *---------------------------------------------------------------------------*/
19
20 #include "pLastError.h"
21 #include "plog.h"
22
printGetLastErrorInternal(const LCHAR * text,char * file,int line)23 void printGetLastErrorInternal(const LCHAR* text, char* file, int line)
24 {
25 #ifdef _WIN32
26 LCHAR* msg;
27
28 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
29 FORMAT_MESSAGE_FROM_SYSTEM |
30 FORMAT_MESSAGE_IGNORE_INSERTS,
31 NULL,
32 GetLastError(),
33 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
34 (LPTSTR) &msg,
35 0,
36 NULL))
37 {
38 ESR_BOOL isInit;
39 ESR_ReturnCode rc;
40 msg[LSTRLEN(msg)-2] = L('\0'); /* cut off newline character */
41
42 rc = PLogIsInitialized(&isInit);
43 if (rc != ESR_SUCCESS)
44 isInit = FALSE;
45 if (isInit)
46 PLogError(L("%s: %s"), text, msg);
47 else
48 pfprintf(PSTDERR, L("[%s:%d] %s: %s\n"), file, line, text, msg);
49 LocalFree(msg);
50 }
51 #elif defined(__vxworks)
52 int err;
53
54 err = errnoGet(); /* get the error status value of the calling task */
55 #ifndef NDEBUG
56 /* printErrno(err); */ /* need special flag to build Simulator */
57 #endif
58 pfprintf(PSTDERR, "[%s:%d] %s, errno = %x\n", file, line, text, err);
59
60 #elif (OS == OS_UNIX)
61
62 #else
63 #error("Have not implemented yet!!!")
64 #endif
65 }
66