gnu-efi: add some more common string functions.

This adds bounded string helper functions:

StrnLen()
StrnCpy()
StrnCat()
StpnCpy()

And the unbounded function StpCpy().

Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
This commit is contained in:
Peter Jones 2018-03-13 15:20:28 -04:00 committed by Nigel Croxon
parent 5abc3858a2
commit 9485c65f6d
4 changed files with 213 additions and 3 deletions

View File

@ -313,17 +313,50 @@ StrCpy (
IN CONST CHAR16 *Src
);
VOID
StrnCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
);
CHAR16 *
StpCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src
);
CHAR16 *
StpnCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
);
VOID
StrCat (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src
);
VOID
StrnCat (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
);
UINTN
StrLen (
IN CONST CHAR16 *s1
);
UINTN
StrnLen (
IN CONST CHAR16 *s1,
IN UINTN Len
);
UINTN
StrSize (
IN CONST CHAR16 *s1

View File

@ -69,6 +69,29 @@ RtStrCpy (
IN CONST CHAR16 *Src
);
VOID
RUNTIMEFUNCTION
RtStrnCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
);
CHAR16 *
RUNTIMEFUNCTION
RtStpCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src
);
CHAR16 *
RUNTIMEFUNCTION
RtStpnCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
);
VOID
RUNTIMEFUNCTION
RtStrCat (
@ -76,12 +99,27 @@ RtStrCat (
IN CONST CHAR16 *Src
);
VOID
RUNTIMEFUNCTION
RtStrnCat (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
);
UINTN
RUNTIMEFUNCTION
RtStrLen (
IN CONST CHAR16 *s1
);
UINTN
RUNTIMEFUNCTION
RtStrnLen (
IN CONST CHAR16 *s1,
IN UINTN Len
);
UINTN
RUNTIMEFUNCTION
RtStrSize (

View File

@ -57,6 +57,61 @@ RtStrCpy (
*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 + Len, '\0', (Len - Size) * sizeof(CHAR16));
RtCopyMem(Dest, Src, Size * sizeof(CHAR16));
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrCpy)
#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(RtStrnCpy)
#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 + Len, '\0', (Len - Size) * sizeof(CHAR16));
RtCopyMem(Dest, Src, Size * sizeof(CHAR16));
return Dest + Size;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrCat)
#endif
@ -66,10 +121,24 @@ RtStrCat (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src
)
{
{
RtStrCpy(Dest+StrLen(Dest), Src);
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrCat)
#endif
VOID
RUNTIMEFUNCTION
RtStrnCat (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
)
{
RtStrnCpy(Dest+StrLen(Dest), Src, Len);
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrLen)
#endif
@ -81,11 +150,28 @@ RtStrLen (
// 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
)
// copy strings
{
UINTN i;
for (i = 0; *s1 && i < Len; i++)
s1++;
return i;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrSize)
#endif
@ -97,7 +183,7 @@ RtStrSize (
// string size
{
UINTN len;
for (len=0; *s1; s1+=1, len+=1) ;
return (len + 1) * sizeof(CHAR16);
}

View File

@ -113,6 +113,38 @@ StrCpy (
RtStrCpy (Dest, Src);
}
VOID
StrnCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
)
// copy strings
{
RtStrnCpy (Dest, Src, Len);
}
CHAR16 *
StpCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src
)
// copy strings
{
return RtStpCpy (Dest, Src);
}
CHAR16 *
StpnCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
)
// copy strings
{
return RtStpnCpy (Dest, Src, Len);
}
VOID
StrCat (
IN CHAR16 *Dest,
@ -122,6 +154,27 @@ StrCat (
RtStrCat(Dest, Src);
}
VOID
StrnCat (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
)
{
RtStrnCat(Dest, Src, Len);
}
UINTN
StrnLen (
IN CONST CHAR16 *s1,
IN UINTN Len
)
// string length
{
return RtStrnLen(s1, Len);
}
UINTN
StrLen (
IN CONST CHAR16 *s1