ReactOS  0.4.14-dev-342-gdc047f9
Log.c
Go to the documentation of this file.
1 #include "Log.h"
2 #include <stdarg.h>
3 #include <stdio.h>
4 #pragma hdrstop
5 
6 BOOLEAN LogMessage(PCHAR szFormat, ...)
7 {
9  char messagebuf[256];
10  va_list va;
12  OBJECT_ATTRIBUTES objectAttributes;
15  UNICODE_STRING fileName;
16 
17 
18  //format the string
19  va_start(va,szFormat);
20  vsprintf(messagebuf,szFormat,va);
21  va_end(va);
22 
23  //get a handle to the log file object
24  fileName.Buffer = NULL;
25  fileName.Length = 0;
26  fileName.MaximumLength = sizeof(DEFAULT_LOG_FILE_NAME) + sizeof(UNICODE_NULL);
27  fileName.Buffer = ExAllocatePool(PagedPool,
28  fileName.MaximumLength);
29  if (!fileName.Buffer)
30  {
31  return FALSE;
32  }
33  RtlZeroMemory(fileName.Buffer, fileName.MaximumLength);
35 
36  //DbgPrint("\n Initializing Object attributes");
37 
38  InitializeObjectAttributes (&objectAttributes,
39  (PUNICODE_STRING)&fileName,
41  NULL,
42  NULL );
43 
44  DbgPrint("\n BusLogic - Creating the file");
45 
46  status = ZwCreateFile(&FileHandle,
48  &objectAttributes,
49  &IoStatus,
50  0,
55  NULL,
56  0 );
57 
58  if(NT_SUCCESS(status))
59  {
60  CHAR buf[300];
63 
64  DbgPrint("\n BusLogic - Created the file");
65 
66  //put a time stamp on the output message
67  sprintf(buf,"%10u-%10u %s",time.HighPart,time.LowPart,messagebuf);
68 
69  //format the string to make sure it appends a newline carriage-return to the
70  //end of the string.
71  Length=strlen(buf);
72  if(buf[Length-1]=='\n')
73  {
74  buf[Length-1]='\r';
75  strcat(buf,"\n");
76  Length++;
77  }
78  else
79  {
80  strcat(buf,"\r\n");
81  Length+=2;
82  }
83 
84  buf[Length+1] = '\0';
85  DbgPrint("\n BusLogic - Writing to the file");
86  DbgPrint("\n BusLogic - Buf = %s", buf);
87 
88  status = ZwWriteFile(FileHandle,
89  NULL,
90  NULL,
91  NULL,
92  &IoStatus,
93  buf,
94  Length,
95  NULL,
96  NULL );
97 
99  }
100  if (fileName.Buffer)
101  ExFreePool (fileName.Buffer);
102 
103  return STATUS_SUCCESS;
104 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
signed char * PCHAR
Definition: retypes.h:7
#define FILE_OPEN_IF
Definition: from_kernel.h:56
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
#define DbgPrint
Definition: loader.c:25
USHORT MaximumLength
Definition: env_spec_w32.h:370
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
uint16_t * PWSTR
Definition: typedefs.h:54
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
__u16 time
Definition: mkdosfs.c:366
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
BOOLEAN LogMessage(PCHAR szFormat,...)
Definition: Log.c:6
#define FILE_APPEND_DATA
Definition: nt_native.h:634
#define sprintf(buf, format,...)
Definition: sprintf.c:55
HANDLE FileHandle
Definition: stats.c:38
#define va_end(ap)
Definition: acmsvcex.h:90
#define UNICODE_NULL
#define DEFAULT_LOG_FILE_NAME
Definition: Log.h:3
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define SYNCHRONIZE
Definition: nt_native.h:61
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
Definition: ps.c:97