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.

67 lines
2.2 KiB

  1. /*****************************************************************************
  2. Natural Language Group Common Library
  3. CMN_CreateFileW.c - windows 95 safe version of CreateFileW
  4. History:
  5. DougP 11/20/97 Created
  6. 1997 Microsoft Corporation
  7. *****************************************************************************/
  8. #include "precomp.h"
  9. #undef CMN_CreateFileW
  10. #undef CreateFileW
  11. HANDLE WINAPI
  12. CMN_CreateFileW (
  13. PCWSTR pwzFileName, // pointer to name of the file
  14. DWORD dwDesiredAccess, // access (read-write) mode
  15. DWORD dwShareMode, // share mode
  16. LPSECURITY_ATTRIBUTES pSecurityAttributes, // pointer to security descriptor
  17. DWORD dwCreationDistribution, // how to create
  18. DWORD dwFlagsAndAttributes, // file attributes
  19. HANDLE hTemplateFile) // handle to file with attributes to copy
  20. {
  21. HINSTANCE hFile;
  22. Assert(pwzFileName);
  23. hFile = CreateFileW (
  24. pwzFileName, // pointer to name of the file
  25. dwDesiredAccess, // access (read-write) mode
  26. dwShareMode, // share mode
  27. pSecurityAttributes, // pointer to security descriptor
  28. dwCreationDistribution, // how to create
  29. dwFlagsAndAttributes, // file attributes
  30. hTemplateFile);
  31. #if defined(_M_IX86)
  32. if (!hFile && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
  33. { // must be in win95 - arghhh!
  34. char szFileName[MAX_PATH];
  35. // Lenox convinced me this is a safe limit for w95
  36. //(if it's NT we're not here)
  37. BOOL fcharerr;
  38. char chdef = ' ';
  39. int res = WideCharToMultiByte (CP_ACP, 0, pwzFileName,
  40. -1,
  41. szFileName, sizeof(szFileName), &chdef, &fcharerr);
  42. if (res && !fcharerr)
  43. hFile = CreateFileA (
  44. szFileName, // pointer to name of the file
  45. dwDesiredAccess, // access (read-write) mode
  46. dwShareMode, // share mode
  47. pSecurityAttributes, // pointer to security descriptor
  48. dwCreationDistribution, // how to create
  49. dwFlagsAndAttributes, // file attributes
  50. hTemplateFile);
  51. else if (fcharerr)
  52. SetLastError(ERROR_NO_UNICODE_TRANSLATION);
  53. }
  54. #endif
  55. #if defined(_DEBUG)
  56. if (!hFile || hFile == INVALID_HANDLE_VALUE)
  57. CMN_OutputSystemErrW(L"Can't CreateFile", pwzFileName);
  58. #endif
  59. return hFile;
  60. }