IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8598


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()

Location:
trunk/psLib/src/sys
Files:
2 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;
  • trunk/psLib/src/sys/psString.h

    r7901 r8598  
    1414 *  @author David Robbins, MHPCC
    1515 *
    16  *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
    17  *  @date $Date: 2006-07-14 02:26:25 $
     16 *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
     17 *  @date $Date: 2006-08-25 21:49:47 $
    1818 *
    1919 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2424
    2525#include <sys/types.h>
     26#include <stdarg.h>
    2627#include "psType.h"
    2728#include "psList.h"
     
    100101);
    101102
     103/** Appends a format onto a string
     104 *
     105 * This function shall allocate a new string if dest is NULL.  dest shall be
     106 * automatically extended to the size of the new string.
     107 *
     108 * @return ssize_t:     The length of the new string (excluding '\0')
     109 */
     110ssize_t psStringAppendV(
     111    char **dest,                        ///< existing string
     112    const char *format,                 ///< format to append
     113    va_list ap                          ///< va_list of format arguments
     114);
     115
    102116/** Prepends a format onto a string
    103117 *
Note: See TracChangeset for help on using the changeset viewer.