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.

194 lines
2.7 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. runtime.c
  5. Abstract:
  6. Implementation of runtime library functions
  7. Environment:
  8. Fax driver, kernel and user mode
  9. Revision History:
  10. 01/09/96 -davidx-
  11. Created it.
  12. mm/dd/yy -author-
  13. description
  14. --*/
  15. #include "faxlib.h"
  16. VOID
  17. CopyStringW(
  18. PWSTR pDest,
  19. PWSTR pSrc,
  20. INT destSize
  21. )
  22. /*++
  23. Routine Description:
  24. Copy Unicode string from source to destination
  25. Arguments:
  26. pDest - Points to the destination buffer
  27. pSrc - Points to source string
  28. destSize - Size of destination buffer (in characters)
  29. Return Value:
  30. NONE
  31. Note:
  32. If the source string is shorter than the destination buffer,
  33. unused chars in the destination buffer is filled with NUL.
  34. --*/
  35. {
  36. PWSTR pEnd;
  37. Assert(pDest != NULL && pSrc != NULL && destSize > 0);
  38. pEnd = pDest + (destSize - 1);
  39. while (pDest < pEnd && (*pDest++ = *pSrc++) != NUL)
  40. ;
  41. while (pDest <= pEnd)
  42. *pDest++ = NUL;
  43. }
  44. VOID
  45. CopyStringA(
  46. PSTR pDest,
  47. PSTR pSrc,
  48. INT destSize
  49. )
  50. /*++
  51. Routine Description:
  52. Copy Ansi string from source to destination
  53. Arguments:
  54. pDest - Points to the destination buffer
  55. pSrc - Points to source string
  56. destSize - Size of destination buffer (in characters)
  57. Return Value:
  58. NONE
  59. Note:
  60. If the source string is shorter than the destination buffer,
  61. unused chars in the destination buffer is filled with NUL.
  62. --*/
  63. {
  64. PSTR pEnd;
  65. Assert(pDest != NULL && pSrc != NULL && destSize > 0);
  66. pEnd = pDest + (destSize - 1);
  67. while (pDest < pEnd && (*pDest++ = *pSrc++) != NUL)
  68. ;
  69. while (pDest <= pEnd)
  70. *pDest++ = NUL;
  71. }
  72. LPTSTR
  73. DuplicateString(
  74. LPCTSTR pSrcStr
  75. )
  76. /*++
  77. Routine Description:
  78. Make a duplicate of the given character string
  79. Arguments:
  80. pSrcStr - Specifies the string to be duplicated
  81. Return Value:
  82. Pointer to the duplicated string, NULL if there is an error
  83. --*/
  84. {
  85. LPTSTR pDestStr;
  86. INT strSize;
  87. if (pSrcStr != NULL) {
  88. strSize = SizeOfString(pSrcStr);
  89. if (pDestStr = MemAlloc(strSize))
  90. CopyMemory(pDestStr, pSrcStr, strSize);
  91. else
  92. Error(("Memory allocation failed\n"));
  93. } else
  94. pDestStr = NULL;
  95. return pDestStr;
  96. }
  97. PCSTR
  98. StripDirPrefixA(
  99. PCSTR pFilename
  100. )
  101. /*++
  102. Routine Description:
  103. Strip the directory prefix off a filename (ANSI version)
  104. Arguments:
  105. pFilename Pointer to filename string
  106. Return Value:
  107. Pointer to the last component of a filename (without directory prefix)
  108. --*/
  109. {
  110. LPCSTR pstr;
  111. if (pstr = strrchr(pFilename, PATH_SEPARATOR))
  112. return pstr + 1;
  113. return pFilename;
  114. }