summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2019-09-20 12:12:06 -0700
committerCommit Bot <commit-bot@chromium.org>2019-10-01 07:41:19 +0000
commit620b7164dddf12df27d5380d647c921853c036dc (patch)
treee16ca0c0cac257259b599133d0f10eccde583b9f /common
parent34b58efd6a434a6530a224458a00ec207ed9ba88 (diff)
downloadchrome-ec-620b7164dddf12df27d5380d647c921853c036dc.tar.gz
utils: Add strstr
The strstr API searches for s2 in s1 and returns the pointer to the substring found in s1. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=none BRANCH=none TEST=make run-utils_str Change-Id: I30f5e8d03e304d28dd6e9bfeebfcaeee2e79ea85 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1818727 Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Auto-Submit: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/util.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/common/util.c b/common/util.c
index 40a107883e..b9f11aad27 100644
--- a/common/util.c
+++ b/common/util.c
@@ -94,6 +94,31 @@ __stdlib_compat int strncasecmp(const char *s1, const char *s2, size_t size)
}
+__stdlib_compat char *strstr(const char *s1, const char *s2)
+{
+ const char *p, *q, *r;
+ size_t len1 = strlen(s1);
+ size_t len2 = strlen(s2);
+
+ if (len1 == 0 || len2 == 0 || len1 < len2)
+ return NULL;
+
+ r = s1 + len1 - len2 + 1;
+ for (; s1 < r; s1++) {
+ if (*s1 == *s2) {
+ p = s1 + 1;
+ q = s2 + 1;
+ for (; q < s2 + len2;) {
+ if (*p++ != *q++)
+ break;
+ }
+ if (*q == '\0')
+ return (char *)s1;
+ }
+ }
+ return NULL;
+}
+
__stdlib_compat int atoi(const char *nptr)
{
int result = 0;