1 /*
2  * %CopyrightBegin%
3  *
4  * Copyright Ericsson AB 1998-2016. All Rights Reserved.
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  * You may obtain a copy of the License at
9  *
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  * %CopyrightEnd%
19  */
20 #include "elog_global.h"
21 #include "elog_util.h"
22 
23 char *category_tab[] = {
24   SYSTEM,
25   APPLICATION,
26   SECURITY,
27   NULL
28 };
29 
30 SeverityEntry severity_tab[] = {
31   {EVENTLOG_ERROR_TYPE , "Error"},
32   {EVENTLOG_WARNING_TYPE, "Warning"},
33   {EVENTLOG_INFORMATION_TYPE, "Informational"},
34   {EVENTLOG_AUDIT_SUCCESS, "Audit_Success"},
35   {EVENTLOG_AUDIT_FAILURE, "Audit_Faulure"},
36   {0, "Severity_Unknown"}
37 };
38 
39 int severity_tab_len =
40 sizeof(severity_tab)/sizeof(SeverityEntry);
41 
lookup_severity(WORD severity)42 char *lookup_severity(WORD severity){
43   int i;
44   for(i=0;i<severity_tab_len-1;++i)
45     if(severity_tab[i].type == severity)
46       return severity_tab[i].desc;
47   return severity_tab[i].desc;
48 }
49 
50 
output_error(DWORD error,char * extra)51 void output_error(DWORD error, char *extra){
52     char *msgbuf;
53     FormatMessage(
54 		  FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
55 		  NULL,
56 		  error,
57 		  DEFAULT_LANGID,
58 		  (LPTSTR) &msgbuf,
59 		  0,
60 		  NULL );
61     fprintf(stderr,"%s: %s", extra, msgbuf);
62     LocalFree(msgbuf);
63 }
64 
65 
66 #undef malloc
my_malloc(size_t siz)67 void *my_malloc(size_t siz){
68   void *x;
69   if((x = malloc(siz)) == NULL){
70     fputs("Out of memory.", stderr);
71     exit(1);
72   }
73   return x;
74 }
75