aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorNicholas Piggin <npiggin@gmail.com>2019-05-10 14:46:26 +1000
committerStewart Smith <stewart@linux.ibm.com>2019-05-20 14:20:29 +1000
commitbc0a30f0bc58ef1406e595d101b70c067b80ea53 (patch)
tree080b45157ce100f52236ebd860ccfa286b585a99 /libc
parent27d1ef2ebabb07a1958b94049cac3d90a101c3d5 (diff)
downloadskiboot-bc0a30f0bc58ef1406e595d101b70c067b80ea53.zip
skiboot-bc0a30f0bc58ef1406e595d101b70c067b80ea53.tar.gz
skiboot-bc0a30f0bc58ef1406e595d101b70c067b80ea53.tar.bz2
libfdt: upgrade to upstream dtc.git 243176c
Upgrade libfdt/ to github.com/dgibson/dtc.git 243176c ("Fix bogus error on rebuild") This copies dtc/libfdt/ to skiboot/libfdt/, with the only change in that directory being the addition of README.skiboot and Makefile.inc. This adds about 14kB text, 2.5kB compressed xz. This could be reduced or mostly eliminated by cutting out fdt version checks and unused code, but tracking upstream is a bigger benefit at the moment. This loses commits: 14ed2b842f61 ("libfdt: add basic sanity check to fdt_open_into") bc7bb3d12bc1 ("sparse: fix declaration of fdt_strerror") As well as some prehistoric similar kinds of things, which is the punishment for us not being good downstream citizens and sending things upstream! Syncing to upstream will make that effort simpler in future. Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
Diffstat (limited to 'libc')
-rw-r--r--libc/include/limits.h3
-rw-r--r--libc/include/string.h1
-rw-r--r--libc/string/Makefile.inc2
-rw-r--r--libc/string/strrchr.c28
-rw-r--r--libc/test/run-memops-test.c7
-rw-r--r--libc/test/run-memops.c7
6 files changed, 47 insertions, 1 deletions
diff --git a/libc/include/limits.h b/libc/include/limits.h
index d7f8d1a..bd67c7e 100644
--- a/libc/include/limits.h
+++ b/libc/include/limits.h
@@ -30,4 +30,7 @@
#define LONG_MIN ((-LONG_MAX)-1)
#define CHAR_BIT 8
+
+#define UINT32_MAX UINT_MAX
+
#endif
diff --git a/libc/include/string.h b/libc/include/string.h
index 2172bdc..d2597bb 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -24,6 +24,7 @@ int strcasecmp(const char *s1, const char *s2);
int strncasecmp(const char *s1, const char *s2, size_t n);
char *strchr(const char *s, int c);
char *strrchr(const char *s, int c);
+char *strrchr(const char *s, int c);
size_t strlen(const char *s);
size_t strnlen(const char *s, size_t n);
char *strstr(const char *hay, const char *needle);
diff --git a/libc/string/Makefile.inc b/libc/string/Makefile.inc
index 122f5da..26582aa 100644
--- a/libc/string/Makefile.inc
+++ b/libc/string/Makefile.inc
@@ -12,7 +12,7 @@
SUBDIRS += $(LIBCDIR)/string
-STRING_OBJS = strcat.o strchr.o strcmp.o strcpy.o strlen.o \
+STRING_OBJS = strcat.o strchr.o strrchr.o strcmp.o strcpy.o strlen.o \
strncmp.o strncpy.o strstr.o memset.o memcpy.o memcpy_from_ci.o \
memmove.o memchr.o memcmp.o strcasecmp.o strncasecmp.o \
strtok.o strdup.o
diff --git a/libc/string/strrchr.c b/libc/string/strrchr.c
new file mode 100644
index 0000000..6652fad
--- /dev/null
+++ b/libc/string/strrchr.c
@@ -0,0 +1,28 @@
+/******************************************************************************
+ * Copyright (c) 2004, 2008, 2019 IBM Corporation
+ * All rights reserved.
+ * This program and the accompanying materials
+ * are made available under the terms of the BSD License
+ * which accompanies this distribution, and is available at
+ * http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ *****************************************************************************/
+
+#include <string.h>
+
+char *
+strrchr(const char *s, int c)
+{
+ char *last = NULL;
+ char cb = c;
+
+ while (*s != 0) {
+ if (*s == cb)
+ last = (char *)s;
+ s += 1;
+ }
+
+ return last;
+}
diff --git a/libc/test/run-memops-test.c b/libc/test/run-memops-test.c
index cb2d7f8..6303b33 100644
--- a/libc/test/run-memops-test.c
+++ b/libc/test/run-memops-test.c
@@ -32,6 +32,7 @@
#include "../string/strcasecmp.c"
#include "../string/strcat.c"
#include "../string/strchr.c"
+#include "../string/strrchr.c"
#include "../string/strcmp.c"
#include "../string/strcpy.c"
/* #include "../string/strdup.c" */
@@ -48,6 +49,7 @@ int test_memchr(const void *ptr, int c, size_t n, void* expected);
int test_memcmp(const void *ptr1, const void *ptr2, size_t n, int expected);
int test_strcmp(const void *ptr1, const void *ptr2, int expected);
int test_strchr(const char *s, int c, char *expected);
+int test_strrchr(const char *s, int c, char *expected);
int test_strcasecmp(const char *s1, const char *s2, int expected);
int test_strncasecmp(const char *s1, const char *s2, size_t n, int expected);
int test_memmove(void *dest, const void *src, size_t n, const void *r, const void *expected, size_t expected_n);
@@ -85,6 +87,11 @@ int test_strchr(const char *s, int c, char *expected)
return(expected == strchr(s, c));
}
+int test_strrchr(const char *s, int c, char *expected)
+{
+ return(expected == strrchr(s, c));
+}
+
int test_strcasecmp(const char *s1, const char *s2, int expected)
{
return(expected == strcasecmp(s1, s2));
diff --git a/libc/test/run-memops.c b/libc/test/run-memops.c
index 5c425f2..55912ea 100644
--- a/libc/test/run-memops.c
+++ b/libc/test/run-memops.c
@@ -26,6 +26,7 @@ int test_memchr(const void *ptr, int c, size_t n, void* expected);
int test_memcmp(const void *ptr1, const void *ptr2, size_t n, int expected);
int test_strcmp(const void *ptr1, const void *ptr2, int expected);
int test_strchr(const char *s, int c, char *expected);
+int test_strrchr(const char *s, int c, char *expected);
int test_strcasecmp(const char *s1, const char *s2, int expected);
int test_strncasecmp(const char *s1, const char *s2, size_t n, int expected);
int test_memmove(void *dest, const void *src, size_t n, const void *r, const void *expected, size_t expected_n);
@@ -64,6 +65,12 @@ int main(void)
assert(test_strchr(buf, 'a', NULL));
assert(test_strchr(buf, '!', buf+11));
+ assert(test_strrchr(buf, 'H', buf));
+ assert(test_strrchr(buf, 'o', buf+7));
+ assert(test_strrchr(buf, 'a', NULL));
+ assert(test_strrchr(buf, 'l', buf+9));
+ assert(test_strrchr(buf, '!', buf+11));
+
assert(test_strcasecmp(buf, "Hello World!", 0));
assert(test_strcasecmp(buf, "HELLO WORLD!", 0));
assert(test_strcasecmp(buf, "IELLO world!", -1));