public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] StdLib/LibC: add strnlen function wrapper
@ 2021-11-03  8:44 mateusz.mowka
  2021-12-12 21:40 ` [edk2-devel] " Rebecca Cran
  0 siblings, 1 reply; 2+ messages in thread
From: mateusz.mowka @ 2021-11-03  8:44 UTC (permalink / raw)
  To: devel; +Cc: mateusz-mowka, Caleb Reister, Rebecca Cran, Michael D Kinney

From: mateusz-mowka <mateusz.mowka@intel.com>

This patch adds strnlen function wrapper that internally calls
AsciiStrnLenS, which is defined in BaseLib.

Cc: Caleb Reister <caleb.reister@intel.com>
Cc: Rebecca Cran <rebecca@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>

Signed-off-by: Mateusz Mówka <mateusz.mowka@intel.com>
---
 StdLib/Include/string.h   | 11 +++++++++++
 StdLib/LibC/String/Misc.c | 12 ++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/StdLib/Include/string.h b/StdLib/Include/string.h
index 0c80944..07652ca 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, 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..cf680e3 100644
--- a/StdLib/LibC/String/Misc.c
+++ b/StdLib/LibC/String/Misc.c
@@ -99,3 +99,15 @@ strlen(const char *s)
 {
   return (size_t)AsciiStrLen( s);
 }
+
+/** The strnlen function computes the length of the string pointed to by s
+    but at most n
+
+    @return   The strnlen function returns the number of characters that
+              precede the terminating null character but at most n.
+**/
+size_t
+strnlen(const char *s, size_t n)
+{
+  return (size_t)AsciiStrnLenS( s, n);
+}
-- 
2.28.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.

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [edk2-devel] [PATCH] StdLib/LibC: add strnlen function wrapper
  2021-11-03  8:44 [PATCH] StdLib/LibC: add strnlen function wrapper mateusz.mowka
@ 2021-12-12 21:40 ` Rebecca Cran
  0 siblings, 0 replies; 2+ messages in thread
From: Rebecca Cran @ 2021-12-12 21:40 UTC (permalink / raw)
  To: devel, mateusz.mowka; +Cc: Caleb Reister, Rebecca Cran, Michael D Kinney

Sorry for the delay.

You should probably use the same doxygen header in both the .h and .c 
files, with the @param lines.


-- 

Rebecca Cran


On 11/3/21 2:44 AM, mateusz.mowka@intel.com wrote:
> From: mateusz-mowka <mateusz.mowka@intel.com>
>
> This patch adds strnlen function wrapper that internally calls
> AsciiStrnLenS, which is defined in BaseLib.
>
> Cc: Caleb Reister <caleb.reister@intel.com>
> Cc: Rebecca Cran <rebecca@nuviainc.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
>
> Signed-off-by: Mateusz Mówka <mateusz.mowka@intel.com>
> ---
>   StdLib/Include/string.h   | 11 +++++++++++
>   StdLib/LibC/String/Misc.c | 12 ++++++++++++
>   2 files changed, 23 insertions(+)
>
> diff --git a/StdLib/Include/string.h b/StdLib/Include/string.h
> index 0c80944..07652ca 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, 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..cf680e3 100644
> --- a/StdLib/LibC/String/Misc.c
> +++ b/StdLib/LibC/String/Misc.c
> @@ -99,3 +99,15 @@ strlen(const char *s)
>   {
>     return (size_t)AsciiStrLen( s);
>   }
> +
> +/** The strnlen function computes the length of the string pointed to by s
> +    but at most n
> +
> +    @return   The strnlen function returns the number of characters that
> +              precede the terminating null character but at most n.
> +**/
> +size_t
> +strnlen(const char *s, size_t n)
> +{
> +  return (size_t)AsciiStrnLenS( s, n);
> +}

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-12 21:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-03  8:44 [PATCH] StdLib/LibC: add strnlen function wrapper mateusz.mowka
2021-12-12 21:40 ` [edk2-devel] " Rebecca Cran

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox