Index: openssl/crypto/buffer/buffer.c |
=================================================================== |
--- openssl/crypto/buffer/buffer.c (revision 105093) |
+++ openssl/crypto/buffer/buffer.c (working copy) |
@@ -89,10 +89,10 @@ |
OPENSSL_free(a); |
} |
-int BUF_MEM_grow(BUF_MEM *str, int len) |
+int BUF_MEM_grow(BUF_MEM *str, size_t len) |
{ |
char *ret; |
- unsigned int n; |
+ size_t n; |
if (str->length >= len) |
{ |
@@ -125,10 +125,10 @@ |
return(len); |
} |
-int BUF_MEM_grow_clean(BUF_MEM *str, int len) |
+int BUF_MEM_grow_clean(BUF_MEM *str, size_t len) |
{ |
char *ret; |
- unsigned int n; |
+ size_t n; |
if (str->length >= len) |
{ |
@@ -161,3 +161,84 @@ |
} |
return(len); |
} |
+ |
+char *BUF_strdup(const char *str) |
+ { |
+ if (str == NULL) return(NULL); |
+ return BUF_strndup(str, strlen(str)); |
+ } |
+ |
+char *BUF_strndup(const char *str, size_t siz) |
+ { |
+ char *ret; |
+ |
+ if (str == NULL) return(NULL); |
+ |
+ ret=OPENSSL_malloc(siz+1); |
+ if (ret == NULL) |
+ { |
+ BUFerr(BUF_F_BUF_STRNDUP,ERR_R_MALLOC_FAILURE); |
+ return(NULL); |
+ } |
+ BUF_strlcpy(ret,str,siz+1); |
+ return(ret); |
+ } |
+ |
+void *BUF_memdup(const void *data, size_t siz) |
+ { |
+ void *ret; |
+ |
+ if (data == NULL) return(NULL); |
+ |
+ ret=OPENSSL_malloc(siz); |
+ if (ret == NULL) |
+ { |
+ BUFerr(BUF_F_BUF_MEMDUP,ERR_R_MALLOC_FAILURE); |
+ return(NULL); |
+ } |
+ return memcpy(ret, data, siz); |
+ } |
+ |
+size_t BUF_strlcpy(char *dst, const char *src, size_t size) |
+ { |
+ size_t l = 0; |
+ for(; size > 1 && *src; size--) |
+ { |
+ *dst++ = *src++; |
+ l++; |
+ } |
+ if (size) |
+ *dst = '\0'; |
+ return l + strlen(src); |
+ } |
+ |
+size_t BUF_strlcat(char *dst, const char *src, size_t size) |
+ { |
+ size_t l = 0; |
+ for(; size > 0 && *dst; size--, dst++) |
+ 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; |
+ } |
+ } |
+ } |