diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2006-04-10 00:11:30 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2006-04-10 00:11:30 +0000 |
commit | 9befdf1d2072f3366086583462332cf6f2bc1540 (patch) | |
tree | 75b7a912df90b997a0d4100a3ef786113b32a5dc /crypto/buffer/buffer.c | |
parent | 75d44c0452e8807dcd9dd126390dd8df35c57efa (diff) |
New utility function to reverse a buffer, either by copying or in-place.
Diffstat (limited to 'crypto/buffer/buffer.c')
-rw-r--r-- | crypto/buffer/buffer.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/crypto/buffer/buffer.c b/crypto/buffer/buffer.c index 3bf03c7eff..a7fe5ba54f 100644 --- a/crypto/buffer/buffer.c +++ b/crypto/buffer/buffer.c @@ -219,3 +219,26 @@ size_t BUF_strlcat(char *dst, const char *src, size_t size) l++; return l + BUF_strlcpy(dst, src, size); } + +void BUF_reverse(unsigned char *out, unsigned char *in, size_t size) + { + size_t i; + if (in) + { + out += size - 1; + for (i = 0; i < size; i++) + *in++ = *out--; + } + else + { + unsigned char *q; + char c; + q = out + size - 1; + for (i = 0; i < size/2; i++) + { + c = *q; + *q-- = *out; + *out++ = c; + } + } + } |