kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikos Nikoleris <nikos.nikoleris@arm.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, drjones@redhat.com,
	alexandru.elisei@arm.com, andre.przywara@arm.com
Subject: [kvm-unit-tests PATCH 1/4] lib/string: add strnlen and strrchr
Date: Tue, 16 Mar 2021 15:24:02 +0000	[thread overview]
Message-ID: <20210316152405.50363-2-nikos.nikoleris@arm.com> (raw)
In-Reply-To: <20210316152405.50363-1-nikos.nikoleris@arm.com>

This change adds two functions from <string.h> in preparation for an
update in the libfdt.

Signed-off-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
---
 lib/string.h |  4 +++-
 lib/string.c | 23 +++++++++++++++++++++--
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/lib/string.h b/lib/string.h
index 493d51b..8da687e 100644
--- a/lib/string.h
+++ b/lib/string.h
@@ -7,12 +7,14 @@
 #ifndef __STRING_H
 #define __STRING_H
 
-extern unsigned long strlen(const char *buf);
+extern size_t strlen(const char *buf);
+extern size_t strnlen(const char *buf, size_t maxlen);
 extern char *strcat(char *dest, const char *src);
 extern char *strcpy(char *dest, const char *src);
 extern int strcmp(const char *a, const char *b);
 extern int strncmp(const char *a, const char *b, size_t n);
 extern char *strchr(const char *s, int c);
+extern char *strrchr(const char *s, int c);
 extern char *strstr(const char *haystack, const char *needle);
 extern void *memset(void *s, int c, size_t n);
 extern void *memcpy(void *dest, const void *src, size_t n);
diff --git a/lib/string.c b/lib/string.c
index 75257f5..9cd626f 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -7,15 +7,24 @@
 
 #include "libcflat.h"
 
-unsigned long strlen(const char *buf)
+size_t strlen(const char *buf)
 {
-    unsigned long len = 0;
+    size_t len = 0;
 
     while (*buf++)
 	++len;
     return len;
 }
 
+size_t strnlen(const char *buf, size_t maxlen)
+{
+    const char *sc;
+
+    for (sc = buf; maxlen-- && *sc != '\0'; ++sc)
+        /* nothing */;
+    return sc - buf;
+}
+
 char *strcat(char *dest, const char *src)
 {
     char *p = dest;
@@ -55,6 +64,16 @@ char *strchr(const char *s, int c)
     return (char *)s;
 }
 
+char *strrchr(const char *s, int c)
+{
+    const char *last = NULL;
+    do {
+        if (*s != (char)c)
+            last = s;
+    } while (*s++);
+    return (char *)last;
+}
+
 char *strstr(const char *s1, const char *s2)
 {
     size_t l1, l2;
-- 
2.25.1


  reply	other threads:[~2021-03-16 15:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-16 15:24 [kvm-unit-tests PATCH 0/4] Fix the devicetree parser for stdout-path Nikos Nikoleris
2021-03-16 15:24 ` Nikos Nikoleris [this message]
2021-03-16 16:04   ` [kvm-unit-tests PATCH 1/4] lib/string: add strnlen and strrchr Andrew Jones
2021-03-16 15:24 ` [kvm-unit-tests PATCH 3/4] Makefile: Avoid double definition of libfdt_clean Nikos Nikoleris
2021-03-16 15:24 ` [kvm-unit-tests PATCH 4/4] devicetree: Parse correctly the stdout-path Nikos Nikoleris
     [not found] ` <20210316152405.50363-3-nikos.nikoleris@arm.com>
2021-03-16 16:12   ` [kvm-unit-tests PATCH 2/4] libfdt: Pull v1.6.0 Andrew Jones
2021-03-16 17:03 ` [kvm-unit-tests PATCH 0/4] Fix the devicetree parser for stdout-path Andrew Jones
2021-03-16 18:54   ` Nikos Nikoleris
2021-03-16 19:01     ` Andrew Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210316152405.50363-2-nikos.nikoleris@arm.com \
    --to=nikos.nikoleris@arm.com \
    --cc=alexandru.elisei@arm.com \
    --cc=andre.przywara@arm.com \
    --cc=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).