summaryrefslogtreecommitdiff
path: root/lib/libcrypto/buffer
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2008-09-06 12:17:55 +0000
committerDamien Miller <djm@cvs.openbsd.org>2008-09-06 12:17:55 +0000
commit96de7a4399a8c71cbb70d6252fa77acfd76b3f09 (patch)
treee6f6e4aad1952944ccd27e9eb47ea48b9a78dde7 /lib/libcrypto/buffer
parentec7710fe8f10fb624fbc33c0bbad2474e0c26979 (diff)
resolve conflicts
Diffstat (limited to 'lib/libcrypto/buffer')
-rw-r--r--lib/libcrypto/buffer/buf_err.c12
-rw-r--r--lib/libcrypto/buffer/buffer.c31
-rw-r--r--lib/libcrypto/buffer/buffer.h17
3 files changed, 46 insertions, 14 deletions
diff --git a/lib/libcrypto/buffer/buf_err.c b/lib/libcrypto/buffer/buf_err.c
index 1fc32a68618..3e25bbe8798 100644
--- a/lib/libcrypto/buffer/buf_err.c
+++ b/lib/libcrypto/buffer/buf_err.c
@@ -70,9 +70,12 @@
static ERR_STRING_DATA BUF_str_functs[]=
{
+{ERR_FUNC(BUF_F_BUF_MEMDUP), "BUF_memdup"},
{ERR_FUNC(BUF_F_BUF_MEM_GROW), "BUF_MEM_grow"},
+{ERR_FUNC(BUF_F_BUF_MEM_GROW_CLEAN), "BUF_MEM_grow_clean"},
{ERR_FUNC(BUF_F_BUF_MEM_NEW), "BUF_MEM_new"},
{ERR_FUNC(BUF_F_BUF_STRDUP), "BUF_strdup"},
+{ERR_FUNC(BUF_F_BUF_STRNDUP), "BUF_strndup"},
{0,NULL}
};
@@ -85,15 +88,12 @@ static ERR_STRING_DATA BUF_str_reasons[]=
void ERR_load_BUF_strings(void)
{
- static int init=1;
+#ifndef OPENSSL_NO_ERR
- if (init)
+ if (ERR_func_error_string(BUF_str_functs[0].error) == NULL)
{
- init=0;
-#ifndef OPENSSL_NO_ERR
ERR_load_strings(0,BUF_str_functs);
ERR_load_strings(0,BUF_str_reasons);
-#endif
-
}
+#endif
}
diff --git a/lib/libcrypto/buffer/buffer.c b/lib/libcrypto/buffer/buffer.c
index d96487e7dbd..3bf03c7eff0 100644
--- a/lib/libcrypto/buffer/buffer.c
+++ b/lib/libcrypto/buffer/buffer.c
@@ -149,7 +149,7 @@ int BUF_MEM_grow_clean(BUF_MEM *str, int len)
ret=OPENSSL_realloc_clean(str->data,str->max,n);
if (ret == NULL)
{
- BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE);
+ BUFerr(BUF_F_BUF_MEM_GROW_CLEAN,ERR_R_MALLOC_FAILURE);
len=0;
}
else
@@ -164,22 +164,41 @@ int BUF_MEM_grow_clean(BUF_MEM *str, int 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;
- int n;
if (str == NULL) return(NULL);
- n=strlen(str);
- ret=OPENSSL_malloc(n+1);
+ ret=OPENSSL_malloc(siz+1);
if (ret == NULL)
{
- BUFerr(BUF_F_BUF_STRDUP,ERR_R_MALLOC_FAILURE);
+ BUFerr(BUF_F_BUF_STRNDUP,ERR_R_MALLOC_FAILURE);
return(NULL);
}
- memcpy(ret,str,n+1);
+ 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;
diff --git a/lib/libcrypto/buffer/buffer.h b/lib/libcrypto/buffer/buffer.h
index 465dc34f3fe..1db96074503 100644
--- a/lib/libcrypto/buffer/buffer.h
+++ b/lib/libcrypto/buffer/buffer.h
@@ -59,25 +59,35 @@
#ifndef HEADER_BUFFER_H
#define HEADER_BUFFER_H
+#include <openssl/ossl_typ.h>
+
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
+
+#if !defined(NO_SYS_TYPES_H)
#include <sys/types.h>
+#endif
+
+/* Already declared in ossl_typ.h */
+/* typedef struct buf_mem_st BUF_MEM; */
-typedef struct buf_mem_st
+struct buf_mem_st
{
int length; /* current number of bytes */
char *data;
int max; /* size of buffer */
- } BUF_MEM;
+ };
BUF_MEM *BUF_MEM_new(void);
void BUF_MEM_free(BUF_MEM *a);
int BUF_MEM_grow(BUF_MEM *str, int len);
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);
/* safe string functions */
size_t BUF_strlcpy(char *dst,const char *src,size_t siz);
@@ -93,9 +103,12 @@ void ERR_load_BUF_strings(void);
/* Error codes for the BUF functions. */
/* Function codes. */
+#define BUF_F_BUF_MEMDUP 103
#define BUF_F_BUF_MEM_GROW 100
+#define BUF_F_BUF_MEM_GROW_CLEAN 105
#define BUF_F_BUF_MEM_NEW 101
#define BUF_F_BUF_STRDUP 102
+#define BUF_F_BUF_STRNDUP 104
/* Reason codes. */