Add BUF_strndup() and BUF_memdup(). Not currently used, but I've code
that uses them that I'll commit in a few days.
This commit is contained in:
parent
7ae46c6761
commit
1ae0a83bdd
6
CHANGES
6
CHANGES
@ -4,6 +4,12 @@
|
||||
|
||||
Changes between 0.9.7a and 0.9.8 [xx XXX xxxx]
|
||||
|
||||
*) Add the functions BUF_strndup() and BUF_memdup(). BUF_strndup()
|
||||
works like BUF_strdup() but can be used to duplicate a portion of
|
||||
a string. The copy gets NUL-terminated. BUF_memdup() duplicates
|
||||
a memory area.
|
||||
[Richard Levitte]
|
||||
|
||||
*) Add the function sk_find_ex() which works like sk_find(), but will
|
||||
return an index to an element even if an exact match couldn't be
|
||||
found. The index is guaranteed to point at the element where the
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* crypto/buffer/buf_err.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
* Copyright (c) 1999-2003 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -61,15 +61,16 @@
|
||||
#include <stdio.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/opensslconf.h> /* To see if OPENSSL_NO_ERR is defined */
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
static ERR_STRING_DATA BUF_str_functs[]=
|
||||
{
|
||||
{ERR_PACK(0,BUF_F_BUF_MEMDUP,0), "BUF_memdup"},
|
||||
{ERR_PACK(0,BUF_F_BUF_MEM_GROW,0), "BUF_MEM_grow"},
|
||||
{ERR_PACK(0,BUF_F_BUF_MEM_NEW,0), "BUF_MEM_new"},
|
||||
{ERR_PACK(0,BUF_F_BUF_STRDUP,0), "BUF_strdup"},
|
||||
{ERR_PACK(0,BUF_F_BUF_STRNDUP,0), "BUF_strndup"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
|
@ -163,23 +163,42 @@ 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;
|
||||
|
@ -78,6 +78,8 @@ 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 +95,11 @@ 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_NEW 101
|
||||
#define BUF_F_BUF_STRDUP 102
|
||||
#define BUF_F_BUF_STRNDUP 104
|
||||
|
||||
/* Reason codes. */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user