IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8607


Ignore:
Timestamp:
Aug 25, 2006, 12:42:37 PM (20 years ago)
Author:
jhoblitt
Message:

add psStringPrependV()
change psStringPrepend() to use psStringPrependV()
cleanup param checking in psStringAppend() & psStringAppendV()

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

Legend:

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

    r8598 r8607  
    1313 *  @author David Robbins, MHPCC
    1414 *
    15  *  @version $Revision: 1.42 $ $Name: not supported by cvs2svn $
    16  *  @date $Date: 2006-08-25 21:50:07 $
     15 *  @version $Revision: 1.43 $ $Name: not supported by cvs2svn $
     16 *  @date $Date: 2006-08-25 22:42:37 $
    1717 *
    1818 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    9898                       ...)
    9999{
     100    PS_ASSERT_PTR_NON_NULL(dest, 0);
     101    PS_ASSERT_PTR_NON_NULL(format, 0);
     102
    100103    va_list ap;
    101104    va_start(ap, format);
     
    110113                        va_list ap)
    111114{
     115    PS_ASSERT_PTR_NON_NULL(dest, 0);
    112116    PS_ASSERT_PTR_NON_NULL(format, 0);
     117
    113118    size_t          length;             // complete string length (sans \0)
    114119    size_t          oldLength;          // original string length (sans \0)
    115120    ssize_t         tailLength;         // length of string to append
    116 
    117     if (!dest || !format) {
    118         return 0;
    119     }
    120121
    121122    if (*dest) {
     
    125126    }
    126127
     128    va_list         apCopy;
     129
    127130    // find the size of the string to append
    128     va_list         apCopy;
    129131    // C99 guarentees vsnprintf() to work as expected with size = 0
    130132    va_copy(apCopy, ap);
     
    160162                        ...)
    161163{
     164    PS_ASSERT_PTR_NON_NULL(dest, 0);
    162165    PS_ASSERT_PTR_NON_NULL(format, 0);
    163     va_list         args;
     166
     167    va_list ap;
     168    va_start(ap, format);
     169    ssize_t length = psStringPrependV(dest, format, ap);
     170    va_end(ap);
     171
     172    return length;
     173}
     174
     175ssize_t psStringPrependV(char **dest,
     176                         const char *format,
     177                         va_list ap)
     178{
     179    PS_ASSERT_PTR_NON_NULL(dest, 0);
     180    PS_ASSERT_PTR_NON_NULL(format, 0);
     181
    164182    size_t          length;             // complete string length (sans \0)
    165183    ssize_t         headLength;         // length of string to prepend
    166184    char            *oldDest;           // copy of original string
    167 
    168     if (!dest || !format) {
    169         return 0;
    170     }
    171185
    172186    if (!*dest) {
     
    179193    }
    180194
     195    va_list apCopy;
     196
    181197    // find the size of the string to prepend
    182     va_start(args, format);
    183198    // C99 guarentees vsnprintf() to work as expected with size = 0
    184     headLength = vsnprintf(*dest, 0, format, args);
    185     va_end(args);
     199    va_copy(apCopy, ap);
     200    headLength = vsnprintf(*dest, 0, format, apCopy);
     201    va_end(apCopy);
    186202
    187203    // if the new head is zero length, return the length of the old string.  if
     
    201217
    202218    // copy the new head to the beginning of string
    203     va_start(args, format);
    204     vsnprintf(*dest, length + 1, format, args);
    205     va_end(args);
     219    // XXX this second call to va_copy() isn't strictly nessicary as the
     220    // calling function can't assume we won't modify the va_list.  However, we
     221    // have decided to error on the side of caution.
     222    va_copy(apCopy, ap);
     223    vsnprintf(*dest, length + 1, format, apCopy);
     224    va_end(apCopy);
    206225
    207226    // append the original string
  • trunk/psLib/src/sys/psString.h

    r8598 r8607  
    1414 *  @author David Robbins, MHPCC
    1515 *
    16  *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
    17  *  @date $Date: 2006-08-25 21:49:47 $
     16 *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
     17 *  @date $Date: 2006-08-25 22:42:37 $
    1818 *
    1919 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    127127);
    128128
     129/** Prepends a format onto a string
     130 *
     131 * This function shall allocate a new string if dest is NULL.  dest shall be
     132 * automatically extended to the size of the new string.
     133 *
     134 * @return ssize_t:     The length of the new string (excluding '\0')
     135 */
     136ssize_t psStringPrependV(
     137    char **dest,                        ///< existing string
     138    const char *format,                 ///< format to append
     139    va_list ap                          ///< va_list of format arguments
     140);
     141
    129142/** Procedure to split the input string into a psList of psStrings.
    130143 *
Note: See TracChangeset for help on using the changeset viewer.