rtstr.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. #ifndef __GNUC__
  11. #pragma RUNTIME_CODE(RtAcquireLock)
  12. #endif
  13. INTN
  14. RUNTIMEFUNCTION
  15. RtStrCmp (
  16. IN CONST CHAR16 *s1,
  17. IN CONST CHAR16 *s2
  18. )
  19. // compare strings
  20. {
  21. while (*s1) {
  22. if (*s1 != *s2) {
  23. break;
  24. }
  25. s1 += 1;
  26. s2 += 1;
  27. }
  28. return *s1 - *s2;
  29. }
  30. #ifndef __GNUC__
  31. #pragma RUNTIME_CODE(RtStrCpy)
  32. #endif
  33. VOID
  34. RUNTIMEFUNCTION
  35. RtStrCpy (
  36. IN CHAR16 *Dest,
  37. IN CONST CHAR16 *Src
  38. )
  39. // copy strings
  40. {
  41. while (*Src) {
  42. *(Dest++) = *(Src++);
  43. }
  44. *Dest = 0;
  45. }
  46. #ifndef __GNUC__
  47. #pragma RUNTIME_CODE(RtStrCat)
  48. #endif
  49. VOID
  50. RUNTIMEFUNCTION
  51. RtStrCat (
  52. IN CHAR16 *Dest,
  53. IN CONST CHAR16 *Src
  54. )
  55. {
  56. RtStrCpy(Dest+StrLen(Dest), Src);
  57. }
  58. #ifndef __GNUC__
  59. #pragma RUNTIME_CODE(RtStrLen)
  60. #endif
  61. UINTN
  62. RUNTIMEFUNCTION
  63. RtStrLen (
  64. IN CONST CHAR16 *s1
  65. )
  66. // string length
  67. {
  68. UINTN len;
  69. for (len=0; *s1; s1+=1, len+=1) ;
  70. return len;
  71. }
  72. #ifndef __GNUC__
  73. #pragma RUNTIME_CODE(RtStrSize)
  74. #endif
  75. UINTN
  76. RUNTIMEFUNCTION
  77. RtStrSize (
  78. IN CONST CHAR16 *s1
  79. )
  80. // string size
  81. {
  82. UINTN len;
  83. for (len=0; *s1; s1+=1, len+=1) ;
  84. return (len + 1) * sizeof(CHAR16);
  85. }
  86. #ifndef __GNUC__
  87. #pragma RUNTIME_CODE(RtBCDtoDecimal)
  88. #endif
  89. UINT8
  90. RUNTIMEFUNCTION
  91. RtBCDtoDecimal(
  92. IN UINT8 BcdValue
  93. )
  94. {
  95. UINTN High, Low;
  96. High = BcdValue >> 4;
  97. Low = BcdValue - (High << 4);
  98. return ((UINT8)(Low + (High * 10)));
  99. }
  100. #ifndef __GNUC__
  101. #pragma RUNTIME_CODE(RtDecimaltoBCD)
  102. #endif
  103. UINT8
  104. RUNTIMEFUNCTION
  105. RtDecimaltoBCD (
  106. IN UINT8 DecValue
  107. )
  108. {
  109. UINTN High, Low;
  110. High = DecValue / 10;
  111. Low = DecValue - (High * 10);
  112. return ((UINT8)(Low + (High << 4)));
  113. }