add function fc_strdup

pull/37/head
yuqing 2018-08-27 15:14:53 +08:00
parent e53cbda01b
commit 85cc906b1d
3 changed files with 29 additions and 1 deletions

View File

@ -1,10 +1,11 @@
Version 1.40 2018-08-24
Version 1.40 2018-08-27
* add function conn_pool_parse_server_info and conn_pool_load_server_info
* support directive: #@add_annotation, for example:
#@add_annotation CONFIG_GET /usr/lib/libshmcache.so /etc/libshmcache.conf
* add function fc_split_string and fc_match_delim
* add json_parser.[hc] for parse json array and map
* add function fc_strdup
Version 1.39 2018-07-31
* add #@function REPLACE_VARS

View File

@ -2716,3 +2716,22 @@ bool ends_with(const char *str, const char *needle)
return memcmp(str + start_offset, needle, needle_len) == 0;
}
char *fc_strdup(const char *str, const int len)
{
char *output;
output = (char *)malloc(len + 1);
if (output == NULL) {
logError("file: "__FILE__", line: %d, "
"malloc %d bytes fail",
__LINE__, len + 1);
return NULL;
}
if (len > 0) {
memcpy(output, str, len);
}
*(output + len) = '\0';
return output;
}

View File

@ -791,6 +791,14 @@ bool starts_with(const char *str, const char *needle);
*/
bool ends_with(const char *str, const char *needle);
/** strdup
* parameters:
* str: the string to duplicate
* len: the length of string
* return: the duplicated string, NULL for fail
*/
char *fc_strdup(const char *str, const int len);
#ifdef __cplusplus
}
#endif