Changeset 263


Ignore:
Timestamp:
Mar 2, 2006 9:12:28 PM (18 years ago)
Author:
bennylp
Message:

Added pj_strdup2_with_null

Location:
pjproject/trunk/pjlib/include/pj
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/include/pj/string.h

    r180 r263  
    216216 * Duplicate string and NULL terminate the destination string. 
    217217 * 
    218  * @param pool 
    219  * @param dst 
    220  * @param src 
     218 * @param pool      The pool. 
     219 * @param dst       The string result. 
     220 * @param src       The string to duplicate. 
     221 * 
     222 * @return          The string result. 
    221223 */ 
    222224PJ_IDECL(pj_str_t*) pj_strdup_with_null(pj_pool_t *pool, 
     
    236238                               pj_str_t *dst, 
    237239                               const char *src); 
     240 
     241/** 
     242 * Duplicate string and NULL terminate the destination string. 
     243 * 
     244 * @param pool      The pool. 
     245 * @param dst       The string result. 
     246 * @param src       The string to duplicate. 
     247 * 
     248 * @return          The string result. 
     249 */ 
     250PJ_IDECL(pj_str_t*) pj_strdup2_with_null(pj_pool_t *pool, 
     251                                         pj_str_t *dst, 
     252                                         const char *src); 
     253 
    238254 
    239255/** 
  • pjproject/trunk/pjlib/include/pj/string_i.h

    r180 r263  
    4444                                        const pj_str_t *src) 
    4545{ 
     46    dst->ptr = (char*)pj_pool_alloc(pool, src->slen+1); 
    4647    if (src->slen) { 
    47         dst->ptr = (char*)pj_pool_alloc(pool, src->slen+1); 
    4848        pj_memcpy(dst->ptr, src->ptr, src->slen); 
    49     } else { 
    50         dst->ptr = (char*)pj_pool_alloc(pool, 1); 
    5149    } 
    5250    dst->slen = src->slen; 
     
    6967} 
    7068 
     69PJ_IDEF(pj_str_t*) pj_strdup2_with_null( pj_pool_t *pool, 
     70                                         pj_str_t *dst, 
     71                                         const char *src) 
     72{ 
     73    dst->slen = src ? pj_ansi_strlen(src) : 0; 
     74    dst->ptr = (char*)pj_pool_alloc(pool, dst->slen+1); 
     75    if (dst->slen) { 
     76        pj_memcpy(dst->ptr, src, dst->slen); 
     77    } 
     78    dst->ptr[dst->slen] = '\0'; 
     79    return dst; 
     80} 
    7181 
    7282PJ_IDEF(pj_str_t) pj_strdup3(pj_pool_t *pool, const char *src) 
Note: See TracChangeset for help on using the changeset viewer.