Changeset 8607 for trunk/psLib/src/sys/psString.c
- Timestamp:
- Aug 25, 2006, 12:42:37 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psString.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psString.c
r8598 r8607 13 13 * @author David Robbins, MHPCC 14 14 * 15 * @version $Revision: 1.4 2$ $Name: not supported by cvs2svn $16 * @date $Date: 2006-08-25 2 1:50:07 $15 * @version $Revision: 1.43 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2006-08-25 22:42:37 $ 17 17 * 18 18 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 98 98 ...) 99 99 { 100 PS_ASSERT_PTR_NON_NULL(dest, 0); 101 PS_ASSERT_PTR_NON_NULL(format, 0); 102 100 103 va_list ap; 101 104 va_start(ap, format); … … 110 113 va_list ap) 111 114 { 115 PS_ASSERT_PTR_NON_NULL(dest, 0); 112 116 PS_ASSERT_PTR_NON_NULL(format, 0); 117 113 118 size_t length; // complete string length (sans \0) 114 119 size_t oldLength; // original string length (sans \0) 115 120 ssize_t tailLength; // length of string to append 116 117 if (!dest || !format) {118 return 0;119 }120 121 121 122 if (*dest) { … … 125 126 } 126 127 128 va_list apCopy; 129 127 130 // find the size of the string to append 128 va_list apCopy;129 131 // C99 guarentees vsnprintf() to work as expected with size = 0 130 132 va_copy(apCopy, ap); … … 160 162 ...) 161 163 { 164 PS_ASSERT_PTR_NON_NULL(dest, 0); 162 165 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 175 ssize_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 164 182 size_t length; // complete string length (sans \0) 165 183 ssize_t headLength; // length of string to prepend 166 184 char *oldDest; // copy of original string 167 168 if (!dest || !format) {169 return 0;170 }171 185 172 186 if (!*dest) { … … 179 193 } 180 194 195 va_list apCopy; 196 181 197 // find the size of the string to prepend 182 va_start(args, format);183 198 // 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); 186 202 187 203 // if the new head is zero length, return the length of the old string. if … … 201 217 202 218 // 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); 206 225 207 226 // append the original string
Note:
See TracChangeset
for help on using the changeset viewer.
