add fast_buffer_append_string2
parent
8403f2246c
commit
3c9054f215
|
|
@ -2,6 +2,7 @@
|
|||
#define __FAST_BUFFER_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common_define.h"
|
||||
|
||||
typedef struct fast_buffer {
|
||||
char *data;
|
||||
|
|
@ -55,6 +56,11 @@ static inline int fast_buffer_append_string(FastBuffer *buffer, const char *str)
|
|||
return fast_buffer_append_buff(buffer, str, strlen(str));
|
||||
}
|
||||
|
||||
static inline int fast_buffer_append_string2(FastBuffer *buffer, const string_t *add)
|
||||
{
|
||||
return fast_buffer_append_buff(buffer, add->str, add->len);
|
||||
}
|
||||
|
||||
static inline int fast_buffer_append_buffer(FastBuffer *buffer, FastBuffer *src)
|
||||
{
|
||||
return fast_buffer_append_buff(buffer, src->data, src->length);
|
||||
|
|
|
|||
|
|
@ -165,22 +165,21 @@ void *fast_mpool_alloc(struct fast_mpool_man *mpool, const int size)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int fast_mpool_strdup(struct fast_mpool_man *mpool, string_t *dest,
|
||||
const string_t *src)
|
||||
int fast_mpool_strdup_ex(struct fast_mpool_man *mpool, string_t *dest,
|
||||
const char *src, const int len)
|
||||
{
|
||||
dest->str = (char *)fast_mpool_alloc(mpool, src->len);
|
||||
dest->str = (char *)fast_mpool_alloc(mpool, len);
|
||||
if (dest->str == NULL)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"alloc %d bytes from mpool fail", __LINE__, src->len);
|
||||
"alloc %d bytes from mpool fail", __LINE__, len);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
if (src->len > 0) {
|
||||
memcpy(dest->str, src->str, src->len);
|
||||
if (len > 0) {
|
||||
memcpy(dest->str, src, len);
|
||||
}
|
||||
dest->len = src->len;
|
||||
dest->len = len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,10 +89,41 @@ parameters:
|
|||
mpool: the mpool pointer
|
||||
dest: the dest string (return the alloced memory in dest->str)
|
||||
src: the source string
|
||||
len: the length of the source string
|
||||
return error no, 0 for success, != 0 fail
|
||||
*/
|
||||
int fast_mpool_strdup(struct fast_mpool_man *mpool, string_t *dest,
|
||||
const string_t *src);
|
||||
int fast_mpool_strdup_ex(struct fast_mpool_man *mpool, string_t *dest,
|
||||
const char *src, const int len);
|
||||
|
||||
/**
|
||||
alloc and copy string from the mpool
|
||||
parameters:
|
||||
mpool: the mpool pointer
|
||||
dest: the dest string (return the alloced memory in dest->str)
|
||||
src: the source string
|
||||
return error no, 0 for success, != 0 fail
|
||||
*/
|
||||
static inline int fast_mpool_strdup(struct fast_mpool_man *mpool,
|
||||
string_t *dest, const char *src)
|
||||
{
|
||||
int len;
|
||||
len = (src != NULL) ? strlen(src) : 0;
|
||||
return fast_mpool_strdup_ex(mpool, dest, src, len);
|
||||
}
|
||||
|
||||
/**
|
||||
alloc and copy string from the mpool
|
||||
parameters:
|
||||
mpool: the mpool pointer
|
||||
dest: the dest string (return the alloced memory in dest->str)
|
||||
src: the source string
|
||||
return error no, 0 for success, != 0 fail
|
||||
*/
|
||||
static inline int fast_mpool_strdup2(struct fast_mpool_man *mpool,
|
||||
string_t *dest, const string_t *src)
|
||||
{
|
||||
return fast_mpool_strdup_ex(mpool, dest, src->str, src->len);
|
||||
}
|
||||
|
||||
/**
|
||||
get stats
|
||||
|
|
|
|||
Loading…
Reference in New Issue