diff options
author | Benny Prijono <bennylp@teluu.com> | 2006-03-02 21:12:28 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2006-03-02 21:12:28 +0000 |
commit | 7e1af4a66ce578c9b8d7a4dcd39a3a41e8663b9b (patch) | |
tree | 44edefe34c7bcc732793349d217dabca5b57f2f5 /pjlib | |
parent | 5bd796e66f3ae6049a43e8e3cfc938d37e061174 (diff) |
Added pj_strdup2_with_null
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@263 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib')
-rw-r--r-- | pjlib/include/pj/string.h | 22 | ||||
-rw-r--r-- | pjlib/include/pj/string_i.h | 16 |
2 files changed, 32 insertions, 6 deletions
diff --git a/pjlib/include/pj/string.h b/pjlib/include/pj/string.h index 34134fd6..acc1ddf7 100644 --- a/pjlib/include/pj/string.h +++ b/pjlib/include/pj/string.h @@ -215,9 +215,11 @@ PJ_IDECL(pj_str_t*) pj_strdup(pj_pool_t *pool, /** * Duplicate string and NULL terminate the destination string. * - * @param pool - * @param dst - * @param src + * @param pool The pool. + * @param dst The string result. + * @param src The string to duplicate. + * + * @return The string result. */ PJ_IDECL(pj_str_t*) pj_strdup_with_null(pj_pool_t *pool, pj_str_t *dst, @@ -237,6 +239,20 @@ PJ_IDECL(pj_str_t*) pj_strdup2(pj_pool_t *pool, const char *src); /** + * Duplicate string and NULL terminate the destination string. + * + * @param pool The pool. + * @param dst The string result. + * @param src The string to duplicate. + * + * @return The string result. + */ +PJ_IDECL(pj_str_t*) pj_strdup2_with_null(pj_pool_t *pool, + pj_str_t *dst, + const char *src); + + +/** * Duplicate string. * * @param pool The pool. diff --git a/pjlib/include/pj/string_i.h b/pjlib/include/pj/string_i.h index 928c8852..25fc0368 100644 --- a/pjlib/include/pj/string_i.h +++ b/pjlib/include/pj/string_i.h @@ -43,11 +43,9 @@ PJ_IDEF(pj_str_t*) pj_strdup_with_null( pj_pool_t *pool, pj_str_t *dst, const pj_str_t *src) { + dst->ptr = (char*)pj_pool_alloc(pool, src->slen+1); if (src->slen) { - dst->ptr = (char*)pj_pool_alloc(pool, src->slen+1); pj_memcpy(dst->ptr, src->ptr, src->slen); - } else { - dst->ptr = (char*)pj_pool_alloc(pool, 1); } dst->slen = src->slen; dst->ptr[dst->slen] = '\0'; @@ -68,6 +66,18 @@ PJ_IDEF(pj_str_t*) pj_strdup2(pj_pool_t *pool, return dst; } +PJ_IDEF(pj_str_t*) pj_strdup2_with_null( pj_pool_t *pool, + pj_str_t *dst, + const char *src) +{ + dst->slen = src ? pj_ansi_strlen(src) : 0; + dst->ptr = (char*)pj_pool_alloc(pool, dst->slen+1); + if (dst->slen) { + pj_memcpy(dst->ptr, src, dst->slen); + } + dst->ptr[dst->slen] = '\0'; + return dst; +} PJ_IDEF(pj_str_t) pj_strdup3(pj_pool_t *pool, const char *src) { |