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.

78 lines
1.1 KiB

  1. #include <mytypes.h>
  2. #include <misclib.h>
  3. #include <stdio.h>
  4. #include <malloc.h>
  5. #include <string.h>
  6. #include <stdarg.h>
  7. char *_LogFilename;
  8. FILE *_LogFile;
  9. unsigned _LogFlags;
  10. VOID
  11. _LogStart(
  12. IN char *FileName
  13. )
  14. {
  15. if(_LogFilename = strdup(FileName)) {
  16. // changed to append to match requested behavior
  17. if(_LogFile = fopen(_LogFilename,"at")) {
  18. _Log("\n*** Logging started\n\n");
  19. } else {
  20. free(_LogFilename);
  21. }
  22. }
  23. }
  24. VOID
  25. _LogEnd(
  26. VOID
  27. )
  28. {
  29. if(_LogFile) {
  30. _Log("\n*** Logging terminated\n\n");
  31. //fflush(_LogFile);
  32. fclose(_LogFile);
  33. _LogFile = NULL;
  34. }
  35. }
  36. VOID
  37. _LogSetFlags(
  38. IN unsigned Flags
  39. )
  40. {
  41. _LogFlags = Flags;
  42. }
  43. VOID
  44. _Log(
  45. IN char *FormatString,
  46. ...
  47. )
  48. {
  49. va_list arglist;
  50. if(!_LogFile) {
  51. return;
  52. }
  53. va_start(arglist,FormatString);
  54. vfprintf(_LogFile,FormatString,arglist);
  55. va_end(arglist);
  56. //fflush(_LogFile);
  57. if(_LogFlags & LOGFLAG_CLOSE_REOPEN) {
  58. fclose(_LogFile);
  59. _LogFile = fopen(_LogFilename,"at");
  60. }
  61. }