Debian Codegraph @

gnu-efi/lib/runtime/rtstr.c

raw
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(RtStrCmp)
22 #endif
23 INTN
24 RUNTIMEFUNCTION
25 RtStrCmp (
26 IN CONST CHAR16 *s1p,
27 IN CONST CHAR16 *s2p
28 )
29 // compare strings
30 {
31 CONST UINT16 *s1 = (CONST UINT16 *)s1p;
32 CONST UINT16 *s2 = (CONST UINT16 *)s2p;
33
34 while (*s1) {
35 if (*s1 != *s2) {
36 break;
37 }
38
39 s1 += 1;
40 s2 += 1;
41 }
42
43 return *s1 - *s2;
44 }
45
46 #ifndef __GNUC__
47 #pragma RUNTIME_CODE(RtStrCpy)
48 #endif
49 VOID
50 RUNTIMEFUNCTION
51 RtStrCpy (
52 IN CHAR16 *Dest,
53 IN CONST CHAR16 *Src
54 )
55 // copy strings
56 {
57 while (*Src) {
58 *(Dest++) = *(Src++);
59 }
60 *Dest = 0;
61 }
62
63 #ifndef __GNUC__
64 #pragma RUNTIME_CODE(RtStrnCpy)
65 #endif
66 VOID
67 RUNTIMEFUNCTION
68 RtStrnCpy (
69 IN CHAR16 *Dest,
70 IN CONST CHAR16 *Src,
71 IN UINTN Len
72 )
73 // copy strings
74 {
75 UINTN Size = RtStrnLen(Src, Len);
76 if (Size != Len)
77 RtSetMem(Dest + Size, (Len - Size) * sizeof(CHAR16), '\0');
78 RtCopyMem(Dest, Src, Size * sizeof(CHAR16));
79 }
80
81 #ifndef __GNUC__
82 #pragma RUNTIME_CODE(RtStpCpy)
83 #endif
84 CHAR16 *
85 RUNTIMEFUNCTION
86 RtStpCpy (
87 IN CHAR16 *Dest,
88 IN CONST CHAR16 *Src
89 )
90 // copy strings
91 {
92 while (*Src) {
93 *(Dest++) = *(Src++);
94 }
95 *Dest = 0;
96 return Dest;
97 }
98
99 #ifndef __GNUC__
100 #pragma RUNTIME_CODE(RtStpnCpy)
101 #endif
102 CHAR16 *
103 RUNTIMEFUNCTION
104 RtStpnCpy (
105 IN CHAR16 *Dest,
106 IN CONST CHAR16 *Src,
107 IN UINTN Len
108 )
109 // copy strings
110 {
111 UINTN Size = RtStrnLen(Src, Len);
112 if (Size != Len)
113 RtSetMem(Dest + Size, (Len - Size) * sizeof(CHAR16), '\0');
114 RtCopyMem(Dest, Src, Size * sizeof(CHAR16));
115 return Dest + Size;
116 }
117
118 #ifndef __GNUC__
119 #pragma RUNTIME_CODE(RtStrCat)
120 #endif
121 VOID
122 RUNTIMEFUNCTION
123 RtStrCat (
124 IN CHAR16 *Dest,
125 IN CONST CHAR16 *Src
126 )
127 {
128 RtStrCpy(Dest+RtStrLen(Dest), Src);
129 }
130
131 #ifndef __GNUC__
132 #pragma RUNTIME_CODE(RtStrnCat)
133 #endif
134 VOID
135 RUNTIMEFUNCTION
136 RtStrnCat (
137 IN CHAR16 *Dest,
138 IN CONST CHAR16 *Src,
139 IN UINTN Len
140 )
141 {
142 UINTN DestSize, Size;
143
144 DestSize = RtStrLen(Dest);
145 Size = RtStrnLen(Src, Len);
146 RtCopyMem(Dest + DestSize, Src, Size * sizeof(CHAR16));
147 Dest[DestSize + Size] = '\0';
148 }
149
150 #ifndef __GNUC__
151 #pragma RUNTIME_CODE(RtStrLen)
152 #endif
153 UINTN
154 RUNTIMEFUNCTION
155 RtStrLen (
156 IN CONST CHAR16 *s1
157 )
158 // string length
159 {
160 UINTN len;
161
162 for (len=0; *s1; s1+=1, len+=1) ;
163 return len;
164 }
165
166 #ifndef __GNUC__
167 #pragma RUNTIME_CODE(RtStrnLen)
168 #endif
169 UINTN
170 RUNTIMEFUNCTION
171 RtStrnLen (
172 IN CONST CHAR16 *s1,
173 IN UINTN Len
174 )
175 // string length
176 {
177 UINTN i;
178 for (i = 0; *s1 && i < Len; i++)
179 s1++;
180 return i;
181 }
182
183 #ifndef __GNUC__
184 #pragma RUNTIME_CODE(RtStrSize)
185 #endif
186 UINTN
187 RUNTIMEFUNCTION
188 RtStrSize (
189 IN CONST CHAR16 *s1
190 )
191 // string size
192 {
193 UINTN len;
194
195 for (len=0; *s1; s1+=1, len+=1) ;
196 return (len + 1) * sizeof(CHAR16);
197 }
198
199 #ifndef __GNUC__
200 #pragma RUNTIME_CODE(RtBCDtoDecimal)
201 #endif
202 UINT8
203 RUNTIMEFUNCTION
204 RtBCDtoDecimal(
205 IN UINT8 BcdValue
206 )
207 {
208 UINTN High, Low;
209
210 High = BcdValue >> 4;
211 Low = BcdValue - (High << 4);
212
213 return ((UINT8)(Low + (High * 10)));
214 }
215
216
217 #ifndef __GNUC__
218 #pragma RUNTIME_CODE(RtDecimaltoBCD)
219 #endif
220 UINT8
221 RUNTIMEFUNCTION
222 RtDecimaltoBCD (
223 IN UINT8 DecValue
224 )
225 {
226 UINTN High, Low;
227
228 High = DecValue / 10;
229 Low = DecValue - (High * 10);
230
231 return ((UINT8)(Low + (High << 4)));
232 }
233
234