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.

74 lines
1.9 KiB

  1. #ifndef __COMMALOG_HPP__
  2. #define __COMMALOG_HPP__
  3. /*---------------------------------------------------------------------------
  4. File: CommaLog.hpp
  5. Comments: TError based log file with optional security.
  6. (c) Copyright 1999, Mission Critical Software, Inc., All Rights Reserved
  7. Proprietary and confidential to Mission Critical Software, Inc.
  8. REVISION LOG ENTRY
  9. Revision By: Christy Boles
  10. Revised on 02/15/99 10:49:50
  11. ---------------------------------------------------------------------------
  12. */
  13. #include <stdio.h>
  14. #include <tchar.h>
  15. class CommaDelimitedLog
  16. {
  17. protected:
  18. FILE * fptr;
  19. public:
  20. CommaDelimitedLog() { fptr = NULL; }
  21. BOOL IsOpen() const { return ( fptr != NULL ); }
  22. BOOL LogOpen(TCHAR const * filename, BOOL protect, int mode = 0); // mode 0=overwrite, 1=append
  23. virtual void LogClose() { if ( fptr ) fclose(fptr); }
  24. BOOL MsgWrite(
  25. TCHAR const msg[] ,// in -error message to display
  26. ... // in -printf args to msg pattern
  27. ) const
  28. {
  29. TCHAR suffix[350];
  30. int lenSuffix = sizeof(suffix)/sizeof(TCHAR);
  31. va_list argPtr;
  32. va_start(argPtr, msg);
  33. _vsntprintf(suffix, lenSuffix - 1, msg, argPtr);
  34. suffix[lenSuffix - 1] = '\0';
  35. va_end(argPtr);
  36. return LogWrite(suffix);
  37. }
  38. protected:
  39. BOOL LogWrite(TCHAR const * msg) const
  40. {
  41. int res = -1;
  42. if ( fptr )
  43. {
  44. #ifdef UNICODE
  45. res = fwprintf(
  46. fptr,
  47. L"%s\r\n",
  48. msg );
  49. #else
  50. res = fprintf(
  51. fptr,
  52. "%s\n",
  53. msg );
  54. #endif
  55. fflush( fptr );
  56. }
  57. return ( res >= 0 );
  58. }
  59. };
  60. PSID GetWellKnownSid(DWORD wellKnownAccount);
  61. #endif //__COMMALOG_HPP__