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.

106 lines
2.8 KiB

  1. //
  2. // Just print the result of GetCurrentDirectoryW.
  3. //
  4. #include "windows.h"
  5. #include <stddef.h>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <stdarg.h>
  9. #pragma warning(push)
  10. #pragma warning(disable: 4511)
  11. #pragma warning(disable: 4512)
  12. #include "yvals.h"
  13. #pragma warning(disable: 4663)
  14. #include <vector>
  15. #pragma warning(pop)
  16. #include <string.h>
  17. #include <stdarg.h>
  18. #define NUMBER_OF(x) (sizeof(x)/sizeof((x)[0]))
  19. #define FusionpGetLastWin32Error GetLastError
  20. #define FusionpSetLastWin32Error SetLastError
  21. #include <string.h>
  22. #include <stdarg.h>
  23. BOOL FusionpConvertToBigPath(PCWSTR Path, SIZE_T BufferSize, PWSTR Buffer);
  24. BOOL FusionpSkipBigPathRoot(PCWSTR s, OUT SIZE_T*);
  25. BOOL FusionpAreWeInOSSetupMode(BOOL* pfIsInSetup) { *pfIsInSetup = FALSE; return TRUE; }
  26. extern "C"
  27. {
  28. BOOL WINAPI SxsDllMain(HINSTANCE hInst, DWORD dwReason, PVOID pvReserved);
  29. void __cdecl wmainCRTStartup();
  30. BOOL FusionpInitializeHeap(HINSTANCE hInstance);
  31. VOID FusionpUninitializeHeap();
  32. };
  33. void ExeEntry()
  34. {
  35. if (!::FusionpInitializeHeap(GetModuleHandleW(NULL)))
  36. goto Exit;
  37. ::wmainCRTStartup();
  38. Exit:
  39. FusionpUninitializeHeap();
  40. }
  41. FILE* g_pLogFile;
  42. const static WCHAR g_pszImage[] = L"getcd_bigpath";
  43. void
  44. ReportFailure(
  45. const char* szFormat,
  46. ...
  47. )
  48. {
  49. const DWORD dwLastError = ::FusionpGetLastWin32Error();
  50. va_list ap;
  51. char rgchBuffer[4096];
  52. WCHAR rgchWin32Error[4096];
  53. va_start(ap, szFormat);
  54. _vsnprintf(rgchBuffer, sizeof(rgchBuffer) / sizeof(rgchBuffer[0]), szFormat, ap);
  55. va_end(ap);
  56. if (!::FormatMessageW(
  57. FORMAT_MESSAGE_FROM_SYSTEM,
  58. NULL,
  59. dwLastError,
  60. 0,
  61. rgchWin32Error,
  62. NUMBER_OF(rgchWin32Error),
  63. &ap))
  64. {
  65. const DWORD dwLastError2 = ::FusionpGetLastWin32Error();
  66. _snwprintf(rgchWin32Error, sizeof(rgchWin32Error) / sizeof(rgchWin32Error[0]), L"Error formatting Win32 error %lu\nError from FormatMessage is %lu", dwLastError, dwLastError2);
  67. }
  68. fprintf(stderr, "%ls: %s\n%ls\n", g_pszImage, rgchBuffer, rgchWin32Error);
  69. if (g_pLogFile != NULL)
  70. fprintf(g_pLogFile, "%ls: %s\n%ls\n", g_pszImage, rgchBuffer, rgchWin32Error);
  71. }
  72. extern "C" int __cdecl wmain(int argc, wchar_t** argv)
  73. {
  74. int iReturnStatus = EXIT_FAILURE;
  75. std::vector<WCHAR> cd;
  76. DWORD dw;
  77. cd.resize((1UL << 15) + 1);
  78. cd[0] = 0;
  79. dw = GetCurrentDirectoryW(static_cast<DWORD>(cd.size()), &cd[0]);
  80. if (dw >= cd.size())
  81. {
  82. SetLastError(ERROR_INSUFFICIENT_BUFFER);
  83. dw = 0;
  84. }
  85. if (dw == 0)
  86. {
  87. ::ReportFailure("GetCurrentDirectoryW\n");
  88. goto Exit;
  89. }
  90. printf("%ls\n", &cd[0]);
  91. //Success:
  92. iReturnStatus = EXIT_SUCCESS;
  93. Exit:
  94. return iReturnStatus;
  95. }