1/*++
2
3Copyright (c) 1998  Intel Corporation
4
5Module Name:
6
7    str.c
8
9Abstract:
10
11    String runtime functions
12
13
14Revision History
15
16--*/
17
18#include "lib.h"
19
20#ifndef __GNUC__
21#pragma RUNTIME_CODE(RtAcquireLock)
22#endif
23INTN
24RUNTIMEFUNCTION
25RtStrCmp (
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
46VOID
47RUNTIMEFUNCTION
48RtStrCpy (
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
63VOID
64RUNTIMEFUNCTION
65RtStrCat (
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
76UINTN
77RUNTIMEFUNCTION
78RtStrLen (
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
92UINTN
93RUNTIMEFUNCTION
94RtStrSize (
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
108UINT8
109RUNTIMEFUNCTION
110RtBCDtoDecimal(
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
126UINT8
127RUNTIMEFUNCTION
128RtDecimaltoBCD (
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