IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 29932


Ignore:
Timestamp:
Dec 5, 2010, 9:25:07 PM (15 years ago)
Author:
eugene
Message:

add psStringRealloc function

Location:
trunk/psLib/src/sys
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psString.c

    r19070 r29932  
    4848    psString string = p_psAlloc(file, lineno, func, nChar + 1);
    4949    psMemSetDeallocator(string, (psFreeFunc)stringFree);
     50
     51    return string;
     52}
     53
     54
     55psString p_psStringRealloc(const char *file,
     56                           unsigned int lineno,
     57                           const char *func,
     58                           psString string,
     59                           size_t nChar)
     60{
     61    if (!string) {
     62        string = p_psAlloc(file, lineno, func, nChar + 1);
     63        psMemSetDeallocator(string, (psFreeFunc)stringFree);
     64    } else {
     65        string = p_psRealloc(file, lineno, func, string, nChar + 1);
     66    }
    5067
    5168    return string;
  • trunk/psLib/src/sys/psString.h

    r15523 r29932  
    4040#define PS_FILE_LINE p_psFileLine(__FILE__,__LINE__)
    4141
    42 
    4342/** Allocates a new psString.
    4443 *
     
    6059#endif // ifdef DOXYGEN
    6160
     61/** Reallocate an existing psString (or alloc if not existent)
     62 *
     63 *  @return psString:       string of length n.
     64 */
     65#ifdef DOXYGEN
     66psString psStringRealloc(
     67    psString string,
     68    size_t nChar                        ///< Size of psString to allocate.
     69);
     70#else // ifdef DOXYGEN
     71psString p_psStringRealloc(
     72    const char *file,                   ///< File of caller
     73    unsigned int lineno,                ///< Line number of caller
     74    const char *func,                   ///< Function name of caller
     75    psString string,                    ///< supplied string or NULL
     76    size_t nChar                        ///< Size of psString to allocate.
     77) PS_ATTR_MALLOC;
     78#define psStringRealloc(string, nChar)                          \
     79    p_psStringRealloc(__FILE__, __LINE__, __func__, string, nChar)
     80#endif // ifdef DOXYGEN
    6281
    6382/** Checks the type of a particular pointer.
Note: See TracChangeset for help on using the changeset viewer.