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.

133 lines
2.9 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: cm_misc.cpp
  4. //
  5. // Module: CMPBK32.DLL
  6. //
  7. // Synopsis: Miscellaneous functions.
  8. //
  9. // Copyright (c) 1998 Microsoft Corporation
  10. //
  11. // Author: quintinb created header 08/17/99
  12. //
  13. //+----------------------------------------------------------------------------
  14. // ############################################################################
  15. // INCLUDES
  16. #include "cmmaster.h"
  17. HINSTANCE g_hInst;
  18. #if 0
  19. /*
  20. int MyStrICmpWithRes(HINSTANCE hInst, LPCTSTR psz1, UINT n2) {
  21. LPTSTR psz2;
  22. int iRes;
  23. if (!psz1) {
  24. return (-1);
  25. }
  26. if (!2) {
  27. return (1);
  28. }
  29. psz2 = CmLoadString(hInst,n2);
  30. iRes = lstrcmpi(psz1,psz2);
  31. CmFree(psz2);
  32. return (iRes);
  33. }
  34. */
  35. #endif
  36. //+----------------------------------------------------------------------------
  37. //
  38. // Function: GetBaseDirFromCms
  39. //
  40. // Synopsis: Strips the filename part and sub-directiory from the specified
  41. // src path which is expected to be a fully qualified path to a .CMS
  42. //
  43. // Arguments: LPCSTR pszSrc - The src path and filename
  44. //
  45. // Returns: LPTSTR - Ptr to allocated Base Directory name including trailing "\"
  46. //
  47. // History: nickball Created 3/8/98
  48. //
  49. //+----------------------------------------------------------------------------
  50. LPTSTR GetBaseDirFromCms(LPCSTR pszSrc)
  51. {
  52. LPTSTR pszBase = NULL;
  53. MYDBGASSERT(pszSrc);
  54. if (NULL == pszSrc || 0 == pszSrc[0])
  55. {
  56. return NULL;
  57. }
  58. //
  59. // The source filename should exist
  60. //
  61. HANDLE hFile = CreateFile(pszSrc, 0, FILE_SHARE_READ | FILE_SHARE_WRITE,
  62. NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  63. if (INVALID_HANDLE_VALUE == hFile)
  64. {
  65. MYDBGASSERT(FALSE);
  66. return NULL;
  67. }
  68. CloseHandle(hFile);
  69. //
  70. // File name is good allocate a buffer to work with
  71. //
  72. LPTSTR pszSlash = NULL;
  73. pszBase = (LPTSTR) CmMalloc((_tcslen(pszSrc) +1)*sizeof(TCHAR));
  74. if (pszBase)
  75. {
  76. _tcscpy(pszBase, pszSrc);
  77. pszSlash = CmStrrchr(pszBase,TEXT('\\'));
  78. if (!pszSlash)
  79. {
  80. MYDBGASSERT(FALSE); // should be a full path
  81. CmFree(pszBase);
  82. return NULL;
  83. }
  84. }
  85. else
  86. {
  87. CMASSERTMSG(FALSE, TEXT("GetBaseDirFromCms -- Unable to allocate pszBase."));
  88. return NULL;
  89. }
  90. //
  91. // Null terminate at slash and find next
  92. //
  93. *pszSlash = TEXT('\0');
  94. pszSlash = CmStrrchr(pszBase,TEXT('\\'));
  95. if (!pszSlash)
  96. {
  97. MYDBGASSERT(FALSE); // should be a full path
  98. CmFree(pszBase);
  99. return NULL;
  100. }
  101. //
  102. // Null terminate at slash again and we're done
  103. //
  104. // pszSlash = _tcsinc(pszSlash);
  105. *pszSlash = TEXT('\0');
  106. return pszBase;
  107. }