IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 25, 2006, 11:50:07 AM (20 years ago)
Author:
jhoblitt
Message:

add psStringAppendV()
change psStringAppend() to be a wrapper around psStringAppendV()

File:
1 edited

Legend:

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

    r8415 r8598  
    1313 *  @author David Robbins, MHPCC
    1414 *
    15  *  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
    16  *  @date $Date: 2006-08-18 01:59:13 $
     15 *  @version $Revision: 1.42 $ $Name: not supported by cvs2svn $
     16 *  @date $Date: 2006-08-25 21:50:07 $
    1717 *
    1818 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    9898                       ...)
    9999{
     100    va_list ap;
     101    va_start(ap, format);
     102    ssize_t length = psStringAppendV(dest, format, ap);
     103    va_end(ap);
     104
     105    return length;
     106}
     107
     108ssize_t psStringAppendV(char **dest,
     109                        const char *format,
     110                        va_list ap)
     111{
    100112    PS_ASSERT_PTR_NON_NULL(format, 0);
    101     va_list         args;
    102113    size_t          length;             // complete string length (sans \0)
    103114    size_t          oldLength;          // original string length (sans \0)
     
    115126
    116127    // find the size of the string to append
    117     va_start(args, format);
     128    va_list         apCopy;
    118129    // C99 guarentees vsnprintf() to work as expected with size = 0
    119     tailLength = vsnprintf(*dest, 0, format, args);
    120     va_end(args);
     130    va_copy(apCopy, ap);
     131    tailLength = vsnprintf(*dest, 0, format, apCopy);
     132    va_end(apCopy);
    121133
    122134    // if the new tail is zero length, return the length of the old string.  if
     
    134146
    135147    // append tail + \0
    136     va_start(args, format);
    137     vsnprintf(*dest + oldLength, tailLength + 1, format, args);
    138     va_end(args);
     148    // XXX this second call to va_copy() isn't strictly nessicary as the
     149    // calling function can't assume we won't modify the va_list.  However, we
     150    // have decided to error on the side of caution.
     151    va_copy(apCopy, ap);
     152    vsnprintf(*dest + oldLength, tailLength + 1, format, apCopy);
     153    va_end(apCopy);
    139154
    140155    return length;
Note: See TracChangeset for help on using the changeset viewer.