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.

126 lines
1.7 KiB

  1. /*++
  2. Copyright (c) 1998 Intel Corporation
  3. Module Name:
  4. str.c
  5. Abstract:
  6. String runtime functions
  7. Revision History
  8. --*/
  9. #include "lib.h"
  10. #pragma RUNTIME_CODE(RtAcquireLock)
  11. INTN
  12. RUNTIMEFUNCTION
  13. RtStrCmp (
  14. IN CHAR16 *s1,
  15. IN CHAR16 *s2
  16. )
  17. /* compare strings */
  18. {
  19. while (*s1) {
  20. if (*s1 != *s2) {
  21. break;
  22. }
  23. s1 += 1;
  24. s2 += 1;
  25. }
  26. return *s1 - *s2;
  27. }
  28. #pragma RUNTIME_CODE(RtStrCpy)
  29. VOID
  30. RUNTIMEFUNCTION
  31. RtStrCpy (
  32. IN CHAR16 *Dest,
  33. IN CHAR16 *Src
  34. )
  35. /* copy strings */
  36. {
  37. while (*Src) {
  38. *(Dest++) = *(Src++);
  39. }
  40. *Dest = 0;
  41. }
  42. #pragma RUNTIME_CODE(RtStrCat)
  43. VOID
  44. RUNTIMEFUNCTION
  45. RtStrCat (
  46. IN CHAR16 *Dest,
  47. IN CHAR16 *Src
  48. )
  49. {
  50. RtStrCpy(Dest+StrLen(Dest), Src);
  51. }
  52. #pragma RUNTIME_CODE(RtStrLen)
  53. UINTN
  54. RUNTIMEFUNCTION
  55. RtStrLen (
  56. IN CHAR16 *s1
  57. )
  58. /* string length */
  59. {
  60. UINTN len;
  61. for (len=0; *s1; s1+=1, len+=1) ;
  62. return len;
  63. }
  64. #pragma RUNTIME_CODE(RtStrSize)
  65. UINTN
  66. RUNTIMEFUNCTION
  67. RtStrSize (
  68. IN CHAR16 *s1
  69. )
  70. /* string size */
  71. {
  72. UINTN len;
  73. for (len=0; *s1; s1+=1, len+=1) ;
  74. return (len + 1) * sizeof(CHAR16);
  75. }
  76. #pragma RUNTIME_CODE(RtBCDtoDecimal)
  77. UINT8
  78. RUNTIMEFUNCTION
  79. RtBCDtoDecimal(
  80. IN UINT8 BcdValue
  81. )
  82. {
  83. UINTN High, Low;
  84. High = BcdValue >> 4;
  85. Low = BcdValue - (High << 4);
  86. return ((UINT8)(Low + (High * 10)));
  87. }
  88. #pragma RUNTIME_CODE(RtDecimaltoBCD)
  89. UINT8
  90. RUNTIMEFUNCTION
  91. RtDecimaltoBCD (
  92. IN UINT8 DecValue
  93. )
  94. {
  95. UINTN High, Low;
  96. High = DecValue / 10;
  97. Low = DecValue - (High * 10);
  98. return ((UINT8)(Low + (High << 4)));
  99. }