ReactOS 0.4.16-dev-401-g45b008d
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
6BOOLEAN 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);
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
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.
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}
BOOLEAN LogMessage(PCHAR szFormat,...)
Definition: Log.c:6
#define DEFAULT_LOG_FILE_NAME
Definition: Log.h:3
unsigned char BOOLEAN
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PagedPool
Definition: env_spec_w32.h:308
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define FILE_OPEN_IF
Definition: from_kernel.h:56
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define DbgPrint
Definition: hal.h:12
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
__u16 time
Definition: mkdosfs.c:8
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_APPEND_DATA
Definition: nt_native.h:634
#define UNICODE_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_SUCCESS
Definition: shellext.h:65
USHORT MaximumLength
Definition: env_spec_w32.h:370
Definition: ps.c:97
uint16_t * PWSTR
Definition: typedefs.h:56
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
char CHAR
Definition: xmlstorage.h:175