summaryrefslogtreecommitdiff
path: root/portable/src/pLastError.c
blob: 446be08a8a9f17acc1d837c18bc9368764d24290 (plain)
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
/*---------------------------------------------------------------------------*
 *  pLastError.c  *
 *                                                                           *
 *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
 *                                                                           *
 *  Licensed under the Apache License, Version 2.0 (the 'License');          *
 *  you may not use this file except in compliance with the License.         *
 *                                                                           *
 *  You may obtain a copy of the License at                                  *
 *      http://www.apache.org/licenses/LICENSE-2.0                           *
 *                                                                           *
 *  Unless required by applicable law or agreed to in writing, software      *
 *  distributed under the License is distributed on an 'AS IS' BASIS,        *
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 
 *  See the License for the specific language governing permissions and      *
 *  limitations under the License.                                           *
 *                                                                           *
 *---------------------------------------------------------------------------*/

#include "pLastError.h"
#include "plog.h"

void printGetLastErrorInternal(const LCHAR* text, char* file, int line)
{
#ifdef _WIN32
  LCHAR* msg;
  
  if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
                    FORMAT_MESSAGE_FROM_SYSTEM |
                    FORMAT_MESSAGE_IGNORE_INSERTS,
                    NULL,
                    GetLastError(),
                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
                    (LPTSTR) &msg,
                    0,
                    NULL))
  {
    ESR_BOOL isInit;
    ESR_ReturnCode rc;
    msg[LSTRLEN(msg)-2] = L('\0'); /* cut off newline character */
    
    rc = PLogIsInitialized(&isInit);
    if (rc != ESR_SUCCESS)
      isInit = FALSE;
    if (isInit)
      PLogError(L("%s: %s"), text, msg);
    else
      pfprintf(PSTDERR, L("[%s:%d] %s: %s\n"), file, line, text, msg);
    LocalFree(msg);
  }
#elif defined(__vxworks)
  int err;
  
  err = errnoGet(); /* get the error status value of the calling task */
#ifndef NDEBUG
  /*  printErrno(err); */ /* need special flag to build Simulator */
#endif
  pfprintf(PSTDERR, "[%s:%d] %s, errno = %x\n", file, line, text, err);
  
#elif (OS == OS_UNIX)

#else
#error("Have not implemented yet!!!")
#endif
}