Subversion Repositories HelenOS

Rev

Rev 2726 | Details | Compare with Previous | Last modification | View Log | RSS feed

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