Leaked source code of windows server 2003
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.

73 lines
1.6 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. SimpleFp.h
  5. Abstract:
  6. simple FILE*, instead of msvcrt.dll
  7. Author:
  8. Xiaoyu Wu(xiaoyuw) July 2000
  9. Revision History:
  10. --*/
  11. #pragma once
  12. #if SXS_PRECOMPILED_MANIFESTS_ENABLED
  13. #include <stdio.h>
  14. class CSimpleFileStream
  15. {
  16. public:
  17. HRESULT fopen(PCWSTR pFileName); // can be a file name, "stderr", "stdout"
  18. HRESULT fclose();
  19. static HRESULT printf(const WCHAR *format, ...)
  20. {
  21. HRESULT hr = NOERROR;
  22. va_list ap;
  23. WCHAR rgchBuffer[2048];
  24. int cch;
  25. DWORD cchWritten;
  26. va_start(ap, format);
  27. cch = ::_vsnwprintf(rgchBuffer, NUMBER_OF(rgchBuffer), format, ap);
  28. rgchBuffer[NUMBER_OF(rgchBuffer) - 1] = 0;
  29. va_end(ap);
  30. if (cch < 0) {// error case
  31. // NTRAID#NTBUG9 - 591008 - 2002/03/30 - mgrier - error code should have something
  32. // to do with the errno value
  33. hr = E_UNEXPECTED;
  34. goto Exit;
  35. }
  36. // NTRAID#NTBUG9 - 591008 - 2002/03/30 - mgrier - Missing error check from GetStdHandle call
  37. if( !::WriteConsole(::GetStdHandle(STD_ERROR_HANDLE), rgchBuffer, cch, &cchWritten, NULL))
  38. {
  39. DWORD dwError = ::FusionpGetLastWin32Error();
  40. hr = HRESULT_FROM_WIN32(dwError);
  41. goto Exit;
  42. }
  43. hr = NOERROR;
  44. Exit :
  45. return hr;
  46. }
  47. HRESULT fprintf(const char *format, ...);
  48. HRESULT fwrite(const VOID*, SIZE_T, SIZE_T);
  49. CSimpleFileStream(PCWSTR pFileName);
  50. ~CSimpleFileStream();
  51. private:
  52. HANDLE m_hFile;
  53. };
  54. #endif