Changeset 8598
- Timestamp:
- Aug 25, 2006, 11:50:07 AM (20 years ago)
- Location:
- trunk/psLib/src/sys
- Files:
-
- 2 edited
-
psString.c (modified) (4 diffs)
-
psString.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psString.c
r8415 r8598 13 13 * @author David Robbins, MHPCC 14 14 * 15 * @version $Revision: 1.4 1$ $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 $ 17 17 * 18 18 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 98 98 ...) 99 99 { 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 108 ssize_t psStringAppendV(char **dest, 109 const char *format, 110 va_list ap) 111 { 100 112 PS_ASSERT_PTR_NON_NULL(format, 0); 101 va_list args;102 113 size_t length; // complete string length (sans \0) 103 114 size_t oldLength; // original string length (sans \0) … … 115 126 116 127 // find the size of the string to append 117 va_ start(args, format);128 va_list apCopy; 118 129 // 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); 121 133 122 134 // if the new tail is zero length, return the length of the old string. if … … 134 146 135 147 // 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); 139 154 140 155 return length; -
trunk/psLib/src/sys/psString.h
r7901 r8598 14 14 * @author David Robbins, MHPCC 15 15 * 16 * @version $Revision: 1.2 6$ $Name: not supported by cvs2svn $17 * @date $Date: 2006-0 7-14 02:26:25$16 * @version $Revision: 1.27 $ $Name: not supported by cvs2svn $ 17 * @date $Date: 2006-08-25 21:49:47 $ 18 18 * 19 19 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 24 24 25 25 #include <sys/types.h> 26 #include <stdarg.h> 26 27 #include "psType.h" 27 28 #include "psList.h" … … 100 101 ); 101 102 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 */ 110 ssize_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 102 116 /** Prepends a format onto a string 103 117 *
Note:
See TracChangeset
for help on using the changeset viewer.
