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