summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorPatrick Rudolph <patrick.rudolph@9elements.com>2018-03-29 10:05:34 +0200
committerPatrick Rudolph <siro@das-labor.org>2018-04-03 14:16:16 +0000
commit03c7b05a5a1838da1e792cb127a549358c5193d4 (patch)
treeb6fb3b2c529054838c0574164fe9236236117729 /src/include
parent4783db2cf18c31ab48b219dabe1e04bf7f311d52 (diff)
downloadcoreboot-03c7b05a5a1838da1e792cb127a549358c5193d4.tar.xz
include/string: Add strrchr
Copy strrchr from libpayload. To be used by Cavium's BDK or FDT parsers. Change-Id: Iab7981c25113ed16f1b8130de4935d30c29d2fa5 Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com> Reviewed-on: https://review.coreboot.org/25447 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: David Hendricks <david.hendricks@gmail.com>
Diffstat (limited to 'src/include')
-rw-r--r--src/include/string.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/include/string.h b/src/include/string.h
index 7597323c47..d2d7bb8781 100644
--- a/src/include/string.h
+++ b/src/include/string.h
@@ -66,6 +66,26 @@ static inline char *strconcat(const char *s1, const char *s2)
}
#endif
+/**
+ * Find a character in a string.
+ *
+ * @param s The string.
+ * @param c The character.
+ * @return A pointer to the last occurrence of the character in the
+ * string, or NULL if the character was not encountered within the string.
+ */
+static inline char *strrchr(const char *s, int c)
+{
+ char *p = (char *)s + strlen(s);
+
+ for (; p >= s; p--) {
+ if (*p == c)
+ return p;
+ }
+
+ return NULL;
+}
+
static inline char *strncpy(char *to, const char *from, int count)
{
register char *ret = to;