diff options
author | nagendra modadugu <ngm@google.com> | 2016-03-07 17:56:46 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-03-07 21:56:04 -0800 |
commit | 88e0161583a9fe6481ed0167cbaf28ea27e99b80 (patch) | |
tree | 98dbb5605fe0ffd9ef0cd3c39be2a817cf942e63 /common/util.c | |
parent | 6e0309ffa9019680bb9294d5b154fe14bebc5f22 (diff) | |
download | chrome-ec-88e0161583a9fe6481ed0167cbaf28ea27e99b80.tar.gz |
CR50: move utility method reverse() to common/util.c
reverse() swaps the endian-ness of a buffer of
specified length. This change moves the implementation
to a common location.
BRANCH=none
BUG=chrome-os-partner:43025,chrome-os-partner:47524
TEST=compilation succeeds
Change-Id: If8c97f53cc199d63c1caebbd999e1c099814387e
Signed-off-by: nagendra modadugu <ngm@google.com>
Reviewed-on: https://chromium-review.googlesource.com/331333
Commit-Ready: Nagendra Modadugu <ngm@google.com>
Tested-by: Nagendra Modadugu <ngm@google.com>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'common/util.c')
-rw-r--r-- | common/util.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/common/util.c b/common/util.c index 2b745e8621..9df5b5596f 100644 --- a/common/util.c +++ b/common/util.c @@ -305,6 +305,21 @@ void *memmove(void *dest, const void *src, size_t len) } +void reverse(void *dest, size_t len) +{ + int i; + uint8_t *start = dest; + uint8_t *end = start + len; + + for (i = 0; i < len / 2; ++i) { + uint8_t tmp = *start; + + *start++ = *--end; + *end = tmp; + } +} + + char *strzcpy(char *dest, const char *src, int len) { char *d = dest; |