Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.3 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1994, Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: Log.c
  6. //
  7. // Contents: Logging code.
  8. //
  9. // History: 18-Dec-96 pathal Created.
  10. //
  11. //---------------------------------------------------------------------------
  12. #include "precomp.h"
  13. #if defined(_DEBUG) || defined( TH_LOG)
  14. VOID
  15. ThLogWrite(
  16. HANDLE hLogFile,
  17. WCHAR *pwszLog)
  18. {
  19. DWORD cbToWrite, cbWritten;
  20. PVOID pv;
  21. if (hLogFile != NULL) {
  22. pv = pwszLog;
  23. cbToWrite = lstrlen(pwszLog) * sizeof(WCHAR);
  24. if (!WriteFile( hLogFile, pv, cbToWrite, &cbWritten, NULL) ||
  25. (cbToWrite != cbWritten)) {
  26. wprintf(L"Error: WriteFile word failed with error %d.\r\n", GetLastError());
  27. }
  28. }
  29. }
  30. HANDLE
  31. ThLogOpen(
  32. IN CONST CHAR *pszLogFile)
  33. {
  34. HANDLE hLogFile;
  35. hLogFile = CreateFileA( pszLogFile, GENERIC_WRITE, 0, NULL,
  36. CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  37. if (hLogFile!=INVALID_HANDLE_VALUE) {
  38. WCHAR wszUniBOM[3] = { 0xFEFF, 0, 0 };
  39. ThLogWrite( hLogFile, wszUniBOM );
  40. }
  41. return hLogFile;
  42. }
  43. VOID
  44. ThLogClose(
  45. IN HANDLE hLogFile )
  46. {
  47. if (hLogFile != NULL) {
  48. CloseHandle( hLogFile );
  49. }
  50. }
  51. #endif // defined(_DEBUG) || defined( TH_LOG)