New utility function to reverse a buffer, either by copying or in-place.
authorDr. Stephen Henson <steve@openssl.org>
Mon, 10 Apr 2006 00:11:30 +0000 (00:11 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Mon, 10 Apr 2006 00:11:30 +0000 (00:11 +0000)
crypto/buffer/buffer.c
crypto/buffer/buffer.h

index 3bf03c7..a7fe5ba 100644 (file)
@@ -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;
+                       }
+               }
+       }
index 1db9607..f7acca5 100644 (file)
@@ -88,6 +88,7 @@ int   BUF_MEM_grow_clean(BUF_MEM *str, int len);
 char * BUF_strdup(const char *str);
 char * BUF_strndup(const char *str, size_t siz);
 void * BUF_memdup(const void *data, size_t siz);
+void   BUF_reverse(unsigned char *out, unsigned char *in, size_t siz);
 
 /* safe string functions */
 size_t BUF_strlcpy(char *dst,const char *src,size_t siz);