summaryrefslogtreecommitdiff
path: root/common/util.c
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-05-07 16:24:13 -0700
committerRandall Spangler <rspangler@chromium.org>2012-05-07 16:26:43 -0700
commitcbdd518422ad794b6bf660bc85aff29edf9bdbc2 (patch)
treee4473ad508dfa2d766e1de4b8726ed348f3e7562 /common/util.c
parentd01657060e33bd08b7b544804e1698b0bf4165c0 (diff)
downloadchrome-ec-cbdd518422ad794b6bf660bc85aff29edf9bdbc2.tar.gz
Clean up sysjump struct parsing and add memmove()
Signed-off-by: Randall Spangler <rspangler@chromium.org> BUG=chrome-os-partner:9447 TEST=update from old EC 517 to this one Change-Id: I275b5bf6c4ae1ab6e0c0a05cf9260314d644c79b
Diffstat (limited to 'common/util.c')
-rw-r--r--common/util.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/common/util.c b/common/util.c
index fe30ffa518..47e9ba1226 100644
--- a/common/util.c
+++ b/common/util.c
@@ -144,6 +144,27 @@ void *memset(void *dest, int c, int len)
}
+void *memmove(void *dest, const void *src, int len)
+{
+ if ((uint32_t)dest <= (uint32_t)src ||
+ (uint32_t)dest >= (uint32_t)src + len) {
+ /* Start of destination doesn't overlap source, so just use
+ * memcpy(). */
+ return memcpy(dest, src, len);
+ } else {
+ /* Copy from end, so we don't overwrite the source */
+ char *d = (char *)dest + len;
+ const char *s = (const char *)src + len;
+ /* TODO: optimized version using LDM/STM would be much faster */
+ while (len > 0) {
+ *(--d) = *(--s);
+ len--;
+ }
+ return dest;
+ }
+}
+
+
char *strzcpy(char *dest, const char *src, int len)
{
char *d = dest;