Subversion Repositories HelenOS

Rev

Rev 2726 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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