Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > DoxygenLog.c
Go to the documentation of this file.
00001 #include "Log.h" 00002 #include <stdarg.h> 00003 #include <stdio.h> 00004 #pragma hdrstop 00005 00006 BOOLEAN LogMessage(PCHAR szFormat, ...) 00007 { 00008 ULONG Length; 00009 char messagebuf[256]; 00010 va_list va; 00011 IO_STATUS_BLOCK IoStatus; 00012 OBJECT_ATTRIBUTES objectAttributes; 00013 NTSTATUS status; 00014 HANDLE FileHandle; 00015 UNICODE_STRING fileName; 00016 00017 00018 //format the string 00019 va_start(va,szFormat); 00020 vsprintf(messagebuf,szFormat,va); 00021 va_end(va); 00022 00023 //get a handle to the log file object 00024 fileName.Buffer = NULL; 00025 fileName.Length = 0; 00026 fileName.MaximumLength = sizeof(DEFAULT_LOG_FILE_NAME) + sizeof(UNICODE_NULL); 00027 fileName.Buffer = ExAllocatePool(PagedPool, 00028 fileName.MaximumLength); 00029 if (!fileName.Buffer) 00030 { 00031 return FALSE; 00032 } 00033 RtlZeroMemory(fileName.Buffer, fileName.MaximumLength); 00034 status = RtlAppendUnicodeToString(&fileName, (PWSTR)DEFAULT_LOG_FILE_NAME); 00035 00036 //DbgPrint("\n Initializing Object attributes"); 00037 00038 InitializeObjectAttributes (&objectAttributes, 00039 (PUNICODE_STRING)&fileName, 00040 OBJ_CASE_INSENSITIVE, 00041 NULL, 00042 NULL ); 00043 00044 DbgPrint("\n BusLogic - Creating the file"); 00045 00046 status = ZwCreateFile(&FileHandle, 00047 FILE_APPEND_DATA, 00048 &objectAttributes, 00049 &IoStatus, 00050 0, 00051 FILE_ATTRIBUTE_NORMAL, 00052 FILE_SHARE_WRITE, 00053 FILE_OPEN_IF, 00054 FILE_SYNCHRONOUS_IO_NONALERT, 00055 NULL, 00056 0 ); 00057 00058 if(NT_SUCCESS(status)) 00059 { 00060 CHAR buf[300]; 00061 LARGE_INTEGER time; 00062 KeQuerySystemTime(&time); 00063 00064 DbgPrint("\n BusLogic - Created the file"); 00065 00066 //put a time stamp on the output message 00067 sprintf(buf,"%10u-%10u %s",time.HighPart,time.LowPart,messagebuf); 00068 00069 //format the string to make sure it appends a newline carrage-return to the 00070 //end of the string. 00071 Length=strlen(buf); 00072 if(buf[Length-1]=='\n') 00073 { 00074 buf[Length-1]='\r'; 00075 strcat(buf,"\n"); 00076 Length++; 00077 } 00078 else 00079 { 00080 strcat(buf,"\r\n"); 00081 Length+=2; 00082 } 00083 00084 buf[Length+1] = '\0'; 00085 DbgPrint("\n BusLogic - Writing to the file"); 00086 DbgPrint("\n BusLogic - Buf = %s", buf); 00087 00088 status = ZwWriteFile(FileHandle, 00089 NULL, 00090 NULL, 00091 NULL, 00092 &IoStatus, 00093 buf, 00094 Length, 00095 NULL, 00096 NULL ); 00097 00098 ZwClose(FileHandle); 00099 } 00100 if (fileName.Buffer) 00101 ExFreePool (fileName.Buffer); 00102 00103 return STATUS_SUCCESS; 00104 } Generated on Sat May 26 2012 04:27:01 for ReactOS by
1.7.6.1
|