Date
1 - 3 of 3
[PATCH v1] From: Mateusz Mówka <mateusz.mowka@intel.com> Subject: [edk2-libc] Add strnlen function wrapper
mateusz-mowka
This patch adds strnlen function wrapper that internally
calls AsciiStrnLenS defined in BaseLib.
Signed-off-by: Mateusz Mówka <mateusz.mowka@...>
---
StdLib/Include/string.h | 11 +++++++++++
StdLib/LibC/String/Misc.c | 14 ++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/StdLib/Include/string.h b/StdLib/Include/string.h
index 0c80944..73193aa 100644
--- a/StdLib/Include/string.h
+++ b/StdLib/Include/string.h
@@ -62,6 +62,7 @@
void *memset (void *s, int c, size_t n);
char *strerror (int num);
size_t strlen (const char *);
+ size_t strnlen (const char *s, size_t n);
################ BSD Compatibility Functions
char *strdup (const char *);
@@ -454,6 +455,16 @@ char *strerror(int Num);
**/
size_t strlen(const char *S);
+/** The strnlen function computes the length of a fixed-size string.
+
+ @param[in] S Pointer to the string to determine the length of.
+ @param[in] N Length of a string including the terminating character.
+
+ @return The strnlen function returns the number of characters that
+ precede the terminating null character but not exceeding N.
+**/
+size_t strnlen(const char *S, size_t N);
+
/* ################ BSD Compatibility Functions ####################### */
diff --git a/StdLib/LibC/String/Misc.c b/StdLib/LibC/String/Misc.c
index f024136..8afffce 100644
--- a/StdLib/LibC/String/Misc.c
+++ b/StdLib/LibC/String/Misc.c
@@ -99,3 +99,17 @@ strlen(const char *s)
{
return (size_t)AsciiStrLen( s);
}
+
+/** The strnlen function computes the length of a fixed-size string.
+
+ @param[in] s Pointer to the string to determine the length of.
+ @param[in] n Length of a string including the terminating character.
+
+ @return The strnlen function returns the number of characters that
+ precede the terminating null character but not exceeding N.
+**/
+size_t
+strnlen(const char *s, size_t n)
+{
+ return (size_t)AsciiStrnLenS( s, n);
+}
--
2.34.0.windows.1
---------------------------------------------------------------------
Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN.
Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.
calls AsciiStrnLenS defined in BaseLib.
Signed-off-by: Mateusz Mówka <mateusz.mowka@...>
---
StdLib/Include/string.h | 11 +++++++++++
StdLib/LibC/String/Misc.c | 14 ++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/StdLib/Include/string.h b/StdLib/Include/string.h
index 0c80944..73193aa 100644
--- a/StdLib/Include/string.h
+++ b/StdLib/Include/string.h
@@ -62,6 +62,7 @@
void *memset (void *s, int c, size_t n);
char *strerror (int num);
size_t strlen (const char *);
+ size_t strnlen (const char *s, size_t n);
################ BSD Compatibility Functions
char *strdup (const char *);
@@ -454,6 +455,16 @@ char *strerror(int Num);
**/
size_t strlen(const char *S);
+/** The strnlen function computes the length of a fixed-size string.
+
+ @param[in] S Pointer to the string to determine the length of.
+ @param[in] N Length of a string including the terminating character.
+
+ @return The strnlen function returns the number of characters that
+ precede the terminating null character but not exceeding N.
+**/
+size_t strnlen(const char *S, size_t N);
+
/* ################ BSD Compatibility Functions ####################### */
diff --git a/StdLib/LibC/String/Misc.c b/StdLib/LibC/String/Misc.c
index f024136..8afffce 100644
--- a/StdLib/LibC/String/Misc.c
+++ b/StdLib/LibC/String/Misc.c
@@ -99,3 +99,17 @@ strlen(const char *s)
{
return (size_t)AsciiStrLen( s);
}
+
+/** The strnlen function computes the length of a fixed-size string.
+
+ @param[in] s Pointer to the string to determine the length of.
+ @param[in] n Length of a string including the terminating character.
+
+ @return The strnlen function returns the number of characters that
+ precede the terminating null character but not exceeding N.
+**/
+size_t
+strnlen(const char *s, size_t n)
+{
+ return (size_t)AsciiStrnLenS( s, n);
+}
--
2.34.0.windows.1
---------------------------------------------------------------------
Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN.
Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.
Michael D Kinney
Reviewed-by: Michael D Kinney <michael.d.kinney@...>
toggle quoted message
Show quoted text
-----Original Message-----
From: Mowka, Mateusz <mateusz.mowka@...>
Sent: Wednesday, August 10, 2022 2:24 AM
To: devel@edk2.groups.io
Cc: rebecca@...; Kinney, Michael D <michael.d.kinney@...>; Mowka, Mateusz <mateusz.mowka@...>
Subject: [PATCH v1] From: Mateusz Mówka <mateusz.mowka@...> Subject: [edk2-libc] Add strnlen function wrapper
This patch adds strnlen function wrapper that internally
calls AsciiStrnLenS defined in BaseLib.
Signed-off-by: Mateusz Mówka <mateusz.mowka@...>
---
StdLib/Include/string.h | 11 +++++++++++
StdLib/LibC/String/Misc.c | 14 ++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/StdLib/Include/string.h b/StdLib/Include/string.h
index 0c80944..73193aa 100644
--- a/StdLib/Include/string.h
+++ b/StdLib/Include/string.h
@@ -62,6 +62,7 @@
void *memset (void *s, int c, size_t n);
char *strerror (int num);
size_t strlen (const char *);
+ size_t strnlen (const char *s, size_t n);
################ BSD Compatibility Functions
char *strdup (const char *);
@@ -454,6 +455,16 @@ char *strerror(int Num);
**/
size_t strlen(const char *S);
+/** The strnlen function computes the length of a fixed-size string.
+
+ @param[in] S Pointer to the string to determine the length of.
+ @param[in] N Length of a string including the terminating character.
+
+ @return The strnlen function returns the number of characters that
+ precede the terminating null character but not exceeding N.
+**/
+size_t strnlen(const char *S, size_t N);
+
/* ################ BSD Compatibility Functions ####################### */
diff --git a/StdLib/LibC/String/Misc.c b/StdLib/LibC/String/Misc.c
index f024136..8afffce 100644
--- a/StdLib/LibC/String/Misc.c
+++ b/StdLib/LibC/String/Misc.c
@@ -99,3 +99,17 @@ strlen(const char *s)
{
return (size_t)AsciiStrLen( s);
}
+
+/** The strnlen function computes the length of a fixed-size string.
+
+ @param[in] s Pointer to the string to determine the length of.
+ @param[in] n Length of a string including the terminating character.
+
+ @return The strnlen function returns the number of characters that
+ precede the terminating null character but not exceeding N.
+**/
+size_t
+strnlen(const char *s, size_t n)
+{
+ return (size_t)AsciiStrnLenS( s, n);
+}
--
2.34.0.windows.1