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.

130 lines
3.1 KiB

  1. /***
  2. *makepath.c - create path name from components
  3. *
  4. * Copyright (c) 1987-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * To provide support for creation of full path names from components
  8. *
  9. *Revision History:
  10. * 06-13-87 DFW initial version
  11. * 08-05-87 JCR Changed appended directory delimeter from '/' to '\'.
  12. * 09-24-87 JCR Removed 'const' from declarations (caused cl warnings).
  13. * 12-11-87 JCR Added "_LOAD_DS" to declaration
  14. * 11-20-89 GJF Fixed copyright, indents. Added const to types of
  15. * appropriate args.
  16. * 03-14-90 GJF Replaced _LOAD_DS with _CALLTYPE1 and added #include
  17. * <cruntime.h>.
  18. * 10-04-90 GJF New-style function declarator.
  19. * 06-09-93 KRS Add _MBCS support.
  20. * 12-07-93 CFW Wide char enable.
  21. *
  22. *******************************************************************************/
  23. #include <cruntime.h>
  24. #include <stdlib.h>
  25. #ifdef _MBCS
  26. #include <mbdata.h>
  27. #include <mbstring.h>
  28. #endif
  29. #include <tchar.h>
  30. /***
  31. *void _makepath() - build path name from components
  32. *
  33. *Purpose:
  34. * create a path name from its individual components
  35. *
  36. *Entry:
  37. * _TSCHAR *path - pointer to buffer for constructed path
  38. * _TSCHAR *drive - pointer to drive component, may or may not contain
  39. * trailing ':'
  40. * _TSCHAR *dir - pointer to subdirectory component, may or may not include
  41. * leading and/or trailing '/' or '\' characters
  42. * _TSCHAR *fname - pointer to file base name component
  43. * _TSCHAR *ext - pointer to extension component, may or may not contain
  44. * a leading '.'.
  45. *
  46. *Exit:
  47. * path - pointer to constructed path name
  48. *
  49. *Exceptions:
  50. *
  51. *******************************************************************************/
  52. void __cdecl _tmakepath (
  53. register _TSCHAR *path,
  54. const _TSCHAR *drive,
  55. const _TSCHAR *dir,
  56. const _TSCHAR *fname,
  57. const _TSCHAR *ext
  58. )
  59. {
  60. register const _TSCHAR *p;
  61. /* we assume that the arguments are in the following form (although we
  62. * do not diagnose invalid arguments or illegal filenames (such as
  63. * names longer than 8.3 or with illegal characters in them)
  64. *
  65. * drive:
  66. * A ; or
  67. * A:
  68. * dir:
  69. * \top\next\last\ ; or
  70. * /top/next/last/ ; or
  71. * either of the above forms with either/both the leading
  72. * and trailing / or \ removed. Mixed use of '/' and '\' is
  73. * also tolerated
  74. * fname:
  75. * any valid file name
  76. * ext:
  77. * any valid extension (none if empty or null )
  78. */
  79. /* copy drive */
  80. if (drive && *drive) {
  81. *path++ = *drive;
  82. *path++ = _T(':');
  83. }
  84. /* copy dir */
  85. if ((p = dir) && *p) {
  86. do {
  87. *path++ = *p++;
  88. }
  89. while (*p);
  90. #ifdef _MBCS
  91. if (*(p=_mbsdec(dir,p)) != _T('/') && *p != _T('\\')) {
  92. #else
  93. if (*(p-1) != _T('/') && *(p-1) != _T('\\')) {
  94. #endif
  95. *path++ = _T('\\');
  96. }
  97. }
  98. /* copy fname */
  99. if (p = fname) {
  100. while (*p) {
  101. *path++ = *p++;
  102. }
  103. }
  104. /* copy ext, including 0-terminator - check to see if a '.' needs
  105. * to be inserted.
  106. */
  107. if (p = ext) {
  108. if (*p && *p != _T('.')) {
  109. *path++ = _T('.');
  110. }
  111. while (*path++ = *p++)
  112. ;
  113. }
  114. else {
  115. /* better add the 0-terminator */
  116. *path = _T('\0');
  117. }
  118. }