diff options
author | Steve McIntyre <steve@einval.com> | 2021-03-23 23:49:46 +0000 |
---|---|---|
committer | Steve McIntyre <steve@einval.com> | 2021-03-23 23:49:46 +0000 |
commit | 1251a7ba86fc40a6aad8b4fecdbca2b61808d9fa (patch) | |
tree | 2125fda549aaca55cb49a48d54be77dec7fbf3df /gnu-efi/lib/runtime/rtstr.c | |
parent | 85b409232ce89b34626df9d72abedf5d4f5ccef6 (diff) | |
parent | 031e5cce385d3f96b1caa1d53495332a7eb03749 (diff) | |
download | efi-boot-shim-debian/15.3-1.tar.gz efi-boot-shim-debian/15.3-1.zip |
Update upstream source from tag 'upstream/15.3'debian/15.3-1
Update to upstream version '15.3'
with Debian dir 1b484f1c1ac270604a5a1451b34de4b0865c6211
Diffstat (limited to 'gnu-efi/lib/runtime/rtstr.c')
-rw-r--r-- | gnu-efi/lib/runtime/rtstr.c | 234 |
1 files changed, 234 insertions, 0 deletions
diff --git a/gnu-efi/lib/runtime/rtstr.c b/gnu-efi/lib/runtime/rtstr.c new file mode 100644 index 00000000..962bb32c --- /dev/null +++ b/gnu-efi/lib/runtime/rtstr.c @@ -0,0 +1,234 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + str.c + +Abstract: + + String runtime functions + + +Revision History + +--*/ + +#include "lib.h" + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtStrCmp) +#endif +INTN +RUNTIMEFUNCTION +RtStrCmp ( + IN CONST CHAR16 *s1p, + IN CONST CHAR16 *s2p + ) +// compare strings +{ + CONST UINT16 *s1 = (CONST UINT16 *)s1p; + CONST UINT16 *s2 = (CONST UINT16 *)s2p; + + while (*s1) { + if (*s1 != *s2) { + break; + } + + s1 += 1; + s2 += 1; + } + + return *s1 - *s2; +} + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtStrCpy) +#endif +VOID +RUNTIMEFUNCTION +RtStrCpy ( + IN CHAR16 *Dest, + IN CONST CHAR16 *Src + ) +// copy strings +{ + while (*Src) { + *(Dest++) = *(Src++); + } + *Dest = 0; +} + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtStrnCpy) +#endif +VOID +RUNTIMEFUNCTION +RtStrnCpy ( + IN CHAR16 *Dest, + IN CONST CHAR16 *Src, + IN UINTN Len + ) +// copy strings +{ + UINTN Size = RtStrnLen(Src, Len); + if (Size != Len) + RtSetMem(Dest + Size, (Len - Size) * sizeof(CHAR16), '\0'); + RtCopyMem(Dest, Src, Size * sizeof(CHAR16)); +} + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtStpCpy) +#endif +CHAR16 * +RUNTIMEFUNCTION +RtStpCpy ( + IN CHAR16 *Dest, + IN CONST CHAR16 *Src + ) +// copy strings +{ + while (*Src) { + *(Dest++) = *(Src++); + } + *Dest = 0; + return Dest; +} + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtStpnCpy) +#endif +CHAR16 * +RUNTIMEFUNCTION +RtStpnCpy ( + IN CHAR16 *Dest, + IN CONST CHAR16 *Src, + IN UINTN Len + ) +// copy strings +{ + UINTN Size = RtStrnLen(Src, Len); + if (Size != Len) + RtSetMem(Dest + Size, (Len - Size) * sizeof(CHAR16), '\0'); + RtCopyMem(Dest, Src, Size * sizeof(CHAR16)); + return Dest + Size; +} + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtStrCat) +#endif +VOID +RUNTIMEFUNCTION +RtStrCat ( + IN CHAR16 *Dest, + IN CONST CHAR16 *Src + ) +{ + RtStrCpy(Dest+RtStrLen(Dest), Src); +} + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtStrnCat) +#endif +VOID +RUNTIMEFUNCTION +RtStrnCat ( + IN CHAR16 *Dest, + IN CONST CHAR16 *Src, + IN UINTN Len + ) +{ + UINTN DestSize, Size; + + DestSize = RtStrLen(Dest); + Size = RtStrnLen(Src, Len); + RtCopyMem(Dest + DestSize, Src, Size * sizeof(CHAR16)); + Dest[DestSize + Size] = '\0'; +} + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtStrLen) +#endif +UINTN +RUNTIMEFUNCTION +RtStrLen ( + IN CONST CHAR16 *s1 + ) +// string length +{ + UINTN len; + + for (len=0; *s1; s1+=1, len+=1) ; + return len; +} + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtStrnLen) +#endif +UINTN +RUNTIMEFUNCTION +RtStrnLen ( + IN CONST CHAR16 *s1, + IN UINTN Len + ) +// string length +{ + UINTN i; + for (i = 0; *s1 && i < Len; i++) + s1++; + return i; +} + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtStrSize) +#endif +UINTN +RUNTIMEFUNCTION +RtStrSize ( + IN CONST CHAR16 *s1 + ) +// string size +{ + UINTN len; + + for (len=0; *s1; s1+=1, len+=1) ; + return (len + 1) * sizeof(CHAR16); +} + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtBCDtoDecimal) +#endif +UINT8 +RUNTIMEFUNCTION +RtBCDtoDecimal( + IN UINT8 BcdValue + ) +{ + UINTN High, Low; + + High = BcdValue >> 4; + Low = BcdValue - (High << 4); + + return ((UINT8)(Low + (High * 10))); +} + + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtDecimaltoBCD) +#endif +UINT8 +RUNTIMEFUNCTION +RtDecimaltoBCD ( + IN UINT8 DecValue + ) +{ + UINTN High, Low; + + High = DecValue / 10; + Low = DecValue - (High * 10); + + return ((UINT8)(Low + (High << 4))); +} + + |