efi/libstub: add strrchr function

Message ID 20180301152744.30718-1-robh@kernel.org
State New
Headers show
Series
  • efi/libstub: add strrchr function
Related show

Commit Message

Rob Herring March 1, 2018, 3:27 p.m.
libfdt gained a new dependency on strrchr, so copy the implementation
from lib/string.c.

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Rob Herring <robh@kernel.org>

---
Please ack. This is a dependency for dtc/libfdt sync with upstream.

 drivers/firmware/efi/libstub/string.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

-- 
2.14.1

Comments

Ard Biesheuvel March 1, 2018, 3:48 p.m. | #1
On 1 March 2018 at 15:27, Rob Herring <robh@kernel.org> wrote:
> libfdt gained a new dependency on strrchr, so copy the implementation

> from lib/string.c.

>

> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>

> Signed-off-by: Rob Herring <robh@kernel.org>

> ---

> Please ack. This is a dependency for dtc/libfdt sync with upstream.

>

>  drivers/firmware/efi/libstub/string.c | 17 +++++++++++++++++

>  1 file changed, 17 insertions(+)

>

> diff --git a/drivers/firmware/efi/libstub/string.c b/drivers/firmware/efi/libstub/string.c

> index ed10e3f602c5..c1a7e58a5af7 100644

> --- a/drivers/firmware/efi/libstub/string.c

> +++ b/drivers/firmware/efi/libstub/string.c

> @@ -56,3 +56,20 @@ int strncmp(const char *cs, const char *ct, size_t count)

>         return 0;

>  }

>  #endif

> +

> +#ifndef __HAVE_ARCH_STRRCHR


As discussed over IRC, this #ifndef needs to be dropped.

Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>


> +/**

> + * strrchr - Find the last occurrence of a character in a string

> + * @s: The string to be searched

> + * @c: The character to search for

> + */

> +char *strrchr(const char *s, int c)

> +{

> +       const char *last = NULL;

> +       do {

> +               if (*s == (char)c)

> +                       last = s;

> +       } while (*s++);

> +       return (char *)last;

> +}

> +#endif

> --

> 2.14.1

>

Patch

diff --git a/drivers/firmware/efi/libstub/string.c b/drivers/firmware/efi/libstub/string.c
index ed10e3f602c5..c1a7e58a5af7 100644
--- a/drivers/firmware/efi/libstub/string.c
+++ b/drivers/firmware/efi/libstub/string.c
@@ -56,3 +56,20 @@  int strncmp(const char *cs, const char *ct, size_t count)
 	return 0;
 }
 #endif
+
+#ifndef __HAVE_ARCH_STRRCHR
+/**
+ * strrchr - Find the last occurrence of a character in a string
+ * @s: The string to be searched
+ * @c: The character to search for
+ */
+char *strrchr(const char *s, int c)
+{
+	const char *last = NULL;
+	do {
+		if (*s == (char)c)
+			last = s;
+	} while (*s++);
+	return (char *)last;
+}
+#endif