提交 9befdf1d 编写于 作者: D Dr. Stephen Henson

New utility function to reverse a buffer, either by copying or in-place.

上级 75d44c04
......@@ -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;
}
}
}
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册