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.

88 lines
2.9 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. /***************************************************************************/
  4. /***** Common Library Component - Path Manipulation Routines - 2 ***********/
  5. /***************************************************************************/
  6. /*
  7. ** Purpose:
  8. ** Creates a valid FAT path from two pieces - a dir string (includes
  9. ** drive, colon, root backslash and zero or more subdirs - backslash
  10. ** at end is optional), and a subpath string.
  11. ** Arguments:
  12. ** szDir: string to a volume consisting of a drive letter (upper
  13. ** or lower case), a colon, a root backslash, and zero or more
  14. ** subdirs, optionally ending with a backslash.
  15. ** szSubPath: string for a subpath of zero or more subdirs and a file
  16. ** name separated by backslashes. (No backslash at the beginning.)
  17. ** szBuf: buffer in which to store the constructed FAT path. It
  18. ** have room for cchpBufMax physical characters which will include
  19. ** the zero terminator.
  20. ** cchpBufMax: non-negative maximum number of useable physical
  21. ** characters in szBuf.
  22. ** Returns:
  23. ** fFalse if any of the string buffers are NULL, if szDir does not
  24. ** start with a valid drive letter, colon and root backslash, or
  25. ** if szSubPath starts with a backslash or is invalid, or if there
  26. ** is not enough space in szBuf to store the newly constructed FAT
  27. ** path.
  28. ** fTrue if a valid FAT path can be constructed from the pieces and
  29. ** stored in szBuf.
  30. **
  31. **************************************************************************/
  32. BOOL APIENTRY FMakeFATPathFromDirAndSubPath(szDir, szSubPath,
  33. szBuf, cchpBufMax)
  34. SZ szDir;
  35. SZ szSubPath;
  36. SZ szBuf;
  37. CCHP cchpBufMax;
  38. {
  39. CB cbBackSlash = (CB)0;
  40. SZ szPathTmp;
  41. SZ szLastChar;
  42. CB cb;
  43. AssertDataSeg();
  44. ChkArg(szDir != (SZ)NULL &&
  45. *szDir != '\0', 1, fFalse);
  46. ChkArg(szSubPath != (SZ)NULL, 2, fFalse);
  47. ChkArg(szBuf != (SZ)NULL, 3, fFalse);
  48. ChkArg(cchpBufMax > (CCHP)4, 4, fFalse);
  49. EvalAssert((szLastChar = SzLastChar(szDir)) != (SZ)NULL);
  50. //
  51. // szLastChar could be a lead byte, but lead bytes aren't in the
  52. // ASCII range so we just check for the \ without checking if
  53. // szLastChar is a lead byte.
  54. //
  55. if(*szLastChar != '\\') {
  56. cbBackSlash = (CB)2;
  57. }
  58. cb = strlen(szDir) + strlen(szSubPath) + cbBackSlash + 1;
  59. if ((szPathTmp = SAlloc(cb)) == (SZ)NULL ||
  60. strcpy(szPathTmp, szDir) != szPathTmp ||
  61. (cbBackSlash > 0 &&
  62. SzStrCat(szPathTmp, "\\") != szPathTmp) ||
  63. SzStrCat(szPathTmp, szSubPath) != szPathTmp)
  64. {
  65. if(szPathTmp) {
  66. SFree(szPathTmp);
  67. }
  68. return(fFalse);
  69. }
  70. if (_fullpath(szBuf, szPathTmp, cchpBufMax) == (SZ)NULL)
  71. {
  72. SFree(szPathTmp);
  73. return(fFalse);
  74. }
  75. SFree(szPathTmp);
  76. return fTrue;
  77. }