• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*++
2 
3 Copyright (c) 1998  Intel Corporation
4 
5 Module Name:
6 
7     str.c
8 
9 Abstract:
10 
11     String runtime functions
12 
13 
14 Revision History
15 
16 --*/
17 
18 #include "lib.h"
19 
20 #ifndef __GNUC__
21 #pragma RUNTIME_CODE(RtAcquireLock)
22 #endif
23 INTN
24 RUNTIMEFUNCTION
RtStrCmp(IN CONST CHAR16 * s1,IN CONST CHAR16 * s2)25 RtStrCmp (
26     IN CONST CHAR16   *s1,
27     IN CONST CHAR16   *s2
28     )
29 // compare strings
30 {
31     while (*s1) {
32         if (*s1 != *s2) {
33             break;
34         }
35 
36         s1 += 1;
37         s2 += 1;
38     }
39 
40     return *s1 - *s2;
41 }
42 
43 #ifndef __GNUC__
44 #pragma RUNTIME_CODE(RtStrCpy)
45 #endif
46 VOID
47 RUNTIMEFUNCTION
RtStrCpy(IN CHAR16 * Dest,IN CONST CHAR16 * Src)48 RtStrCpy (
49     IN CHAR16   *Dest,
50     IN CONST CHAR16   *Src
51     )
52 // copy strings
53 {
54     while (*Src) {
55         *(Dest++) = *(Src++);
56     }
57     *Dest = 0;
58 }
59 
60 #ifndef __GNUC__
61 #pragma RUNTIME_CODE(RtStrCat)
62 #endif
63 VOID
64 RUNTIMEFUNCTION
RtStrCat(IN CHAR16 * Dest,IN CONST CHAR16 * Src)65 RtStrCat (
66     IN CHAR16   *Dest,
67     IN CONST CHAR16   *Src
68     )
69 {
70     RtStrCpy(Dest+StrLen(Dest), Src);
71 }
72 
73 #ifndef __GNUC__
74 #pragma RUNTIME_CODE(RtStrLen)
75 #endif
76 UINTN
77 RUNTIMEFUNCTION
RtStrLen(IN CONST CHAR16 * s1)78 RtStrLen (
79     IN CONST CHAR16   *s1
80     )
81 // string length
82 {
83     UINTN        len;
84 
85     for (len=0; *s1; s1+=1, len+=1) ;
86     return len;
87 }
88 
89 #ifndef __GNUC__
90 #pragma RUNTIME_CODE(RtStrSize)
91 #endif
92 UINTN
93 RUNTIMEFUNCTION
RtStrSize(IN CONST CHAR16 * s1)94 RtStrSize (
95     IN CONST CHAR16   *s1
96     )
97 // string size
98 {
99     UINTN        len;
100 
101     for (len=0; *s1; s1+=1, len+=1) ;
102     return (len + 1) * sizeof(CHAR16);
103 }
104 
105 #ifndef __GNUC__
106 #pragma RUNTIME_CODE(RtBCDtoDecimal)
107 #endif
108 UINT8
109 RUNTIMEFUNCTION
RtBCDtoDecimal(IN UINT8 BcdValue)110 RtBCDtoDecimal(
111     IN  UINT8 BcdValue
112     )
113 {
114     UINTN   High, Low;
115 
116     High    = BcdValue >> 4;
117     Low     = BcdValue - (High << 4);
118 
119     return ((UINT8)(Low + (High * 10)));
120 }
121 
122 
123 #ifndef __GNUC__
124 #pragma RUNTIME_CODE(RtDecimaltoBCD)
125 #endif
126 UINT8
127 RUNTIMEFUNCTION
RtDecimaltoBCD(IN UINT8 DecValue)128 RtDecimaltoBCD (
129     IN  UINT8 DecValue
130     )
131 {
132     UINTN   High, Low;
133 
134     High    = DecValue / 10;
135     Low     = DecValue - (High * 10);
136 
137     return ((UINT8)(Low + (High << 4)));
138 }
139 
140 
141