Blame SOURCES/0018-gnu-efi-add-some-more-common-string-functions.patch

ba2c15
From 9485c65f6d28b71ff697849c1c8d47fd077ccd07 Mon Sep 17 00:00:00 2001
ba2c15
From: Peter Jones <pjones@redhat.com>
ba2c15
Date: Tue, 13 Mar 2018 15:20:28 -0400
ba2c15
Subject: [PATCH 18/25] gnu-efi: add some more common string functions.
ba2c15
ba2c15
This adds bounded string helper functions:
ba2c15
ba2c15
StrnLen()
ba2c15
StrnCpy()
ba2c15
StrnCat()
ba2c15
StpnCpy()
ba2c15
ba2c15
And the unbounded function StpCpy().
ba2c15
ba2c15
Signed-off-by: Peter Jones <pjones@redhat.com>
ba2c15
Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
ba2c15
---
ba2c15
 lib/runtime/rtstr.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++--
ba2c15
 lib/str.c           | 53 ++++++++++++++++++++++++++++++
ba2c15
 inc/efilib.h        | 33 +++++++++++++++++++
ba2c15
 inc/efirtlib.h      | 38 ++++++++++++++++++++++
ba2c15
 4 files changed, 213 insertions(+), 3 deletions(-)
ba2c15
ba2c15
diff --git a/lib/runtime/rtstr.c b/lib/runtime/rtstr.c
ba2c15
index e283c09582e..80ff4891199 100644
ba2c15
--- a/lib/runtime/rtstr.c
ba2c15
+++ b/lib/runtime/rtstr.c
ba2c15
@@ -57,6 +57,61 @@ RtStrCpy (
ba2c15
     *Dest = 0;
ba2c15
 }
ba2c15
 
ba2c15
+#ifndef __GNUC__
ba2c15
+#pragma RUNTIME_CODE(RtStrnCpy)
ba2c15
+#endif
ba2c15
+VOID
ba2c15
+RUNTIMEFUNCTION
ba2c15
+RtStrnCpy (
ba2c15
+    IN CHAR16   *Dest,
ba2c15
+    IN CONST CHAR16   *Src,
ba2c15
+    IN UINTN     Len
ba2c15
+    )
ba2c15
+// copy strings
ba2c15
+{
ba2c15
+    UINTN Size = RtStrnLen(Src, Len);
ba2c15
+    if (Size != Len)
ba2c15
+	RtSetMem(Dest + Len, '\0', (Len - Size) * sizeof(CHAR16));
ba2c15
+    RtCopyMem(Dest, Src, Size * sizeof(CHAR16));
ba2c15
+}
ba2c15
+
ba2c15
+#ifndef __GNUC__
ba2c15
+#pragma RUNTIME_CODE(RtStrCpy)
ba2c15
+#endif
ba2c15
+CHAR16 *
ba2c15
+RUNTIMEFUNCTION
ba2c15
+RtStpCpy (
ba2c15
+    IN CHAR16   *Dest,
ba2c15
+    IN CONST CHAR16   *Src
ba2c15
+    )
ba2c15
+// copy strings
ba2c15
+{
ba2c15
+    while (*Src) {
ba2c15
+        *(Dest++) = *(Src++);
ba2c15
+    }
ba2c15
+    *Dest = 0;
ba2c15
+    return Dest;
ba2c15
+}
ba2c15
+
ba2c15
+#ifndef __GNUC__
ba2c15
+#pragma RUNTIME_CODE(RtStrnCpy)
ba2c15
+#endif
ba2c15
+CHAR16 *
ba2c15
+RUNTIMEFUNCTION
ba2c15
+RtStpnCpy (
ba2c15
+    IN CHAR16   *Dest,
ba2c15
+    IN CONST CHAR16   *Src,
ba2c15
+    IN UINTN     Len
ba2c15
+    )
ba2c15
+// copy strings
ba2c15
+{
ba2c15
+    UINTN Size = RtStrnLen(Src, Len);
ba2c15
+    if (Size != Len)
ba2c15
+	RtSetMem(Dest + Len, '\0', (Len - Size) * sizeof(CHAR16));
ba2c15
+    RtCopyMem(Dest, Src, Size * sizeof(CHAR16));
ba2c15
+    return Dest + Size;
ba2c15
+}
ba2c15
+
ba2c15
 #ifndef __GNUC__
ba2c15
 #pragma RUNTIME_CODE(RtStrCat)
ba2c15
 #endif
ba2c15
@@ -66,10 +121,24 @@ RtStrCat (
ba2c15
     IN CHAR16   *Dest,
ba2c15
     IN CONST CHAR16   *Src
ba2c15
     )
ba2c15
-{   
ba2c15
+{
ba2c15
     RtStrCpy(Dest+StrLen(Dest), Src);
ba2c15
 }
ba2c15
 
ba2c15
+#ifndef __GNUC__
ba2c15
+#pragma RUNTIME_CODE(RtStrCat)
ba2c15
+#endif
ba2c15
+VOID
ba2c15
+RUNTIMEFUNCTION
ba2c15
+RtStrnCat (
ba2c15
+    IN CHAR16   *Dest,
ba2c15
+    IN CONST CHAR16   *Src,
ba2c15
+    IN UINTN    Len
ba2c15
+    )
ba2c15
+{
ba2c15
+    RtStrnCpy(Dest+StrLen(Dest), Src, Len);
ba2c15
+}
ba2c15
+
ba2c15
 #ifndef __GNUC__
ba2c15
 #pragma RUNTIME_CODE(RtStrLen)
ba2c15
 #endif
ba2c15
@@ -81,11 +150,28 @@ RtStrLen (
ba2c15
 // string length
ba2c15
 {
ba2c15
     UINTN        len;
ba2c15
-    
ba2c15
+
ba2c15
     for (len=0; *s1; s1+=1, len+=1) ;
ba2c15
     return len;
ba2c15
 }
ba2c15
 
ba2c15
+#ifndef __GNUC__
ba2c15
+#pragma RUNTIME_CODE(RtStrnLen)
ba2c15
+#endif
ba2c15
+UINTN
ba2c15
+RUNTIMEFUNCTION
ba2c15
+RtStrnLen (
ba2c15
+    IN CONST CHAR16   *s1,
ba2c15
+    IN UINTN           Len
ba2c15
+    )
ba2c15
+// copy strings
ba2c15
+{
ba2c15
+    UINTN i;
ba2c15
+    for (i = 0; *s1 && i < Len; i++)
ba2c15
+	    s1++;
ba2c15
+    return i;
ba2c15
+}
ba2c15
+
ba2c15
 #ifndef __GNUC__
ba2c15
 #pragma RUNTIME_CODE(RtStrSize)
ba2c15
 #endif
ba2c15
@@ -97,7 +183,7 @@ RtStrSize (
ba2c15
 // string size
ba2c15
 {
ba2c15
     UINTN        len;
ba2c15
-    
ba2c15
+
ba2c15
     for (len=0; *s1; s1+=1, len+=1) ;
ba2c15
     return (len + 1) * sizeof(CHAR16);
ba2c15
 }
ba2c15
diff --git a/lib/str.c b/lib/str.c
ba2c15
index cf1495c1fc8..9a89f30ee55 100644
ba2c15
--- a/lib/str.c
ba2c15
+++ b/lib/str.c
ba2c15
@@ -113,6 +113,38 @@ StrCpy (
ba2c15
     RtStrCpy (Dest, Src);
ba2c15
 }
ba2c15
 
ba2c15
+VOID
ba2c15
+StrnCpy (
ba2c15
+    IN CHAR16   *Dest,
ba2c15
+    IN CONST CHAR16   *Src,
ba2c15
+    IN UINTN     Len
ba2c15
+    )
ba2c15
+// copy strings
ba2c15
+{
ba2c15
+    RtStrnCpy (Dest, Src, Len);
ba2c15
+}
ba2c15
+
ba2c15
+CHAR16 *
ba2c15
+StpCpy (
ba2c15
+    IN CHAR16   *Dest,
ba2c15
+    IN CONST CHAR16   *Src
ba2c15
+    )
ba2c15
+// copy strings
ba2c15
+{
ba2c15
+    return RtStpCpy (Dest, Src);
ba2c15
+}
ba2c15
+
ba2c15
+CHAR16 *
ba2c15
+StpnCpy (
ba2c15
+    IN CHAR16   *Dest,
ba2c15
+    IN CONST CHAR16   *Src,
ba2c15
+    IN UINTN     Len
ba2c15
+    )
ba2c15
+// copy strings
ba2c15
+{
ba2c15
+    return RtStpnCpy (Dest, Src, Len);
ba2c15
+}
ba2c15
+
ba2c15
 VOID
ba2c15
 StrCat (
ba2c15
     IN CHAR16   *Dest,
ba2c15
@@ -122,6 +154,27 @@ StrCat (
ba2c15
     RtStrCat(Dest, Src);
ba2c15
 }
ba2c15
 
ba2c15
+VOID
ba2c15
+StrnCat (
ba2c15
+    IN CHAR16   *Dest,
ba2c15
+    IN CONST CHAR16   *Src,
ba2c15
+    IN UINTN     Len
ba2c15
+    )
ba2c15
+{
ba2c15
+    RtStrnCat(Dest, Src, Len);
ba2c15
+}
ba2c15
+
ba2c15
+
ba2c15
+UINTN
ba2c15
+StrnLen (
ba2c15
+    IN CONST CHAR16   *s1,
ba2c15
+    IN UINTN           Len
ba2c15
+    )
ba2c15
+// string length
ba2c15
+{
ba2c15
+    return RtStrnLen(s1, Len);
ba2c15
+}
ba2c15
+
ba2c15
 UINTN
ba2c15
 StrLen (
ba2c15
     IN CONST CHAR16   *s1
ba2c15
diff --git a/inc/efilib.h b/inc/efilib.h
ba2c15
index 22da65bbc27..8a507aff7cd 100644
ba2c15
--- a/inc/efilib.h
ba2c15
+++ b/inc/efilib.h
ba2c15
@@ -313,17 +313,50 @@ StrCpy (
ba2c15
     IN CONST CHAR16    *Src
ba2c15
     );
ba2c15
 
ba2c15
+VOID
ba2c15
+StrnCpy (
ba2c15
+    IN CHAR16   *Dest,
ba2c15
+    IN CONST CHAR16    *Src,
ba2c15
+    IN UINTN     Len
ba2c15
+    );
ba2c15
+
ba2c15
+CHAR16 *
ba2c15
+StpCpy (
ba2c15
+    IN CHAR16   *Dest,
ba2c15
+    IN CONST CHAR16    *Src
ba2c15
+    );
ba2c15
+
ba2c15
+CHAR16 *
ba2c15
+StpnCpy (
ba2c15
+    IN CHAR16   *Dest,
ba2c15
+    IN CONST CHAR16    *Src,
ba2c15
+    IN UINTN     Len
ba2c15
+    );
ba2c15
+
ba2c15
 VOID
ba2c15
 StrCat (
ba2c15
     IN CHAR16   *Dest,
ba2c15
     IN CONST CHAR16   *Src
ba2c15
     );
ba2c15
 
ba2c15
+VOID
ba2c15
+StrnCat (
ba2c15
+    IN CHAR16   *Dest,
ba2c15
+    IN CONST CHAR16   *Src,
ba2c15
+    IN UINTN     Len
ba2c15
+    );
ba2c15
+
ba2c15
 UINTN
ba2c15
 StrLen (
ba2c15
     IN CONST CHAR16   *s1
ba2c15
     );
ba2c15
 
ba2c15
+UINTN
ba2c15
+StrnLen (
ba2c15
+    IN CONST CHAR16   *s1,
ba2c15
+    IN UINTN           Len
ba2c15
+    );
ba2c15
+
ba2c15
 UINTN
ba2c15
 StrSize (
ba2c15
     IN CONST CHAR16   *s1
ba2c15
diff --git a/inc/efirtlib.h b/inc/efirtlib.h
ba2c15
index c073ead97a7..49d0b4d3ae0 100644
ba2c15
--- a/inc/efirtlib.h
ba2c15
+++ b/inc/efirtlib.h
ba2c15
@@ -69,6 +69,29 @@ RtStrCpy (
ba2c15
     IN CONST CHAR16    *Src
ba2c15
     );
ba2c15
 
ba2c15
+VOID
ba2c15
+RUNTIMEFUNCTION
ba2c15
+RtStrnCpy (
ba2c15
+    IN CHAR16   *Dest,
ba2c15
+    IN CONST CHAR16    *Src,
ba2c15
+    IN UINTN     Len
ba2c15
+    );
ba2c15
+
ba2c15
+CHAR16 *
ba2c15
+RUNTIMEFUNCTION
ba2c15
+RtStpCpy (
ba2c15
+    IN CHAR16   *Dest,
ba2c15
+    IN CONST CHAR16    *Src
ba2c15
+    );
ba2c15
+
ba2c15
+CHAR16 *
ba2c15
+RUNTIMEFUNCTION
ba2c15
+RtStpnCpy (
ba2c15
+    IN CHAR16   *Dest,
ba2c15
+    IN CONST CHAR16    *Src,
ba2c15
+    IN UINTN     Len
ba2c15
+    );
ba2c15
+
ba2c15
 VOID
ba2c15
 RUNTIMEFUNCTION
ba2c15
 RtStrCat (
ba2c15
@@ -76,12 +99,27 @@ RtStrCat (
ba2c15
     IN CONST CHAR16   *Src
ba2c15
     );
ba2c15
 
ba2c15
+VOID
ba2c15
+RUNTIMEFUNCTION
ba2c15
+RtStrnCat (
ba2c15
+    IN CHAR16   *Dest,
ba2c15
+    IN CONST CHAR16   *Src,
ba2c15
+    IN UINTN     Len
ba2c15
+    );
ba2c15
+
ba2c15
 UINTN
ba2c15
 RUNTIMEFUNCTION
ba2c15
 RtStrLen (
ba2c15
     IN CONST CHAR16   *s1
ba2c15
     );
ba2c15
 
ba2c15
+UINTN
ba2c15
+RUNTIMEFUNCTION
ba2c15
+RtStrnLen (
ba2c15
+    IN CONST CHAR16   *s1,
ba2c15
+    IN UINTN           Len
ba2c15
+    );
ba2c15
+
ba2c15
 UINTN
ba2c15
 RUNTIMEFUNCTION
ba2c15
 RtStrSize (
ba2c15
-- 
ba2c15
2.15.0
ba2c15