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.

124 lines
2.8 KiB

  1. #include <windows.h>
  2. #include "wincestub.h"
  3. #include <streamhlp.h>
  4. #include "wcelib.h"
  5. void *bsearch( const void *key, const void *base, size_t num, size_t width, int ( __cdecl *compare ) ( const void *elem1, const void *elem2 ) )
  6. {
  7. int low=0,
  8. high=num-1,
  9. mid,
  10. res;
  11. while (low<=high)
  12. {
  13. mid= (low+high)>>1;
  14. if ( !(res=compare(key, (BYTE*)base+mid*width)) ) return (BYTE*)base+mid*width;
  15. if (res<0)
  16. {
  17. high=mid-1;
  18. }
  19. else
  20. {
  21. low=mid+1;
  22. }
  23. }
  24. return NULL;
  25. }
  26. DWORD GetFullPathName(WCHAR *lpFileName, // file name
  27. DWORD nBufferLength, // size of path buffer
  28. WCHAR *lpBuffer, // path buffer
  29. WCHAR **lpFilePart // address of file name in path
  30. )
  31. {
  32. DWORD dRes=FALSE;
  33. // check if we already have full name
  34. *lpFilePart=wcsrchr(lpFileName, L'\\');
  35. if (*lpFilePart)
  36. {
  37. wcsncpy(lpBuffer, lpFileName, min(wcslen(lpFileName)+1, nBufferLength));
  38. *lpFilePart = wcsrchr(lpBuffer, L'\\');
  39. (*lpFilePart)++;
  40. dRes=TRUE;
  41. }
  42. else
  43. {
  44. if(::GetModuleFileName(NULL,lpBuffer,nBufferLength))
  45. {
  46. *lpFilePart=wcsrchr(lpBuffer, L'\\');
  47. if(*lpFilePart)
  48. {
  49. *(++(*lpFilePart))=0;
  50. }
  51. DWORD uLen = wcslen(lpBuffer);
  52. wcsncpy(lpBuffer+uLen, lpFileName, min(wcslen(lpFileName)+1, nBufferLength-uLen));
  53. dRes=TRUE;
  54. }
  55. }
  56. return dRes;
  57. }
  58. DWORD GetCurrentDirectory(
  59. DWORD nBufferLength, // size of directory buffer
  60. LPTSTR lpBuffer // directory buffer
  61. )
  62. {
  63. DWORD dRes=FALSE;
  64. LPTSTR lpFilePart=NULL;
  65. if(::GetModuleFileName(NULL,lpBuffer,nBufferLength))
  66. {
  67. lpFilePart=wcsrchr(lpBuffer, L'\\');
  68. if (lpFilePart)
  69. {
  70. *lpFilePart=0;
  71. }
  72. else
  73. {
  74. if (nBufferLength>2)
  75. {
  76. wcscpy(lpBuffer, L"\\");
  77. }
  78. }
  79. dRes=TRUE;
  80. }
  81. return dRes;
  82. }
  83. HRESULT URLOpenBlockingStreamW(
  84. LPUNKNOWN pCaller,
  85. LPCWSTR szURL,
  86. LPSTREAM *ppStream,
  87. DWORD dwReserved,
  88. LPBINDSTATUSCALLBACK lpfnCB
  89. )
  90. {
  91. HRESULT hr=S_OK;
  92. if ( pCaller || dwReserved ) return E_INVALIDARG;
  93. if ( lpfnCB ) return E_NOTIMPL;
  94. CSpFileStream * pNew = new CSpFileStream( &hr,
  95. szURL,
  96. GENERIC_READ,
  97. 0,
  98. OPEN_EXISTING);
  99. if (pNew)
  100. {
  101. if (SUCCEEDED(hr))
  102. {
  103. *ppStream = pNew;
  104. }
  105. }
  106. else
  107. {
  108. hr = E_OUTOFMEMORY;
  109. }
  110. return hr;
  111. }