Changeset 7912 for trunk/psLib/src/sys/psString.c
- Timestamp:
- Jul 14, 2006, 4:50:51 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psString.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psString.c
r7905 r7912 13 13 * @author David Robbins, MHPCC 14 14 * 15 * @version $Revision: 1.3 8$ $Name: not supported by cvs2svn $16 * @date $Date: 2006-07-1 4 20:06:43$15 * @version $Revision: 1.39 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2006-07-15 02:50:51 $ 17 17 * 18 18 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 56 56 { 57 57 // Pass through NULL values! 58 59 // Allocate memory using psAlloc function 58 if (!string) { 59 return NULL; 60 } 61 psString output = psStringAlloc(strlen(string) + 1); // Output string 60 62 // Copy input string to memory just allocated 61 // Return the copy 62 return string ? strcpy(psAlloc(strlen(string) + 1), string) : NULL; 63 return strcpy(output, string); 63 64 } 64 65 … … 67 68 { 68 69 PS_ASSERT_PTR_NON_NULL(string, NULL); 69 char *returnValue = NULL; 70 71 // Pass through NULL values 72 if (!string) { 73 return NULL; 74 } 70 75 71 76 // Check the number of characters to copy is non-negative … … 77 82 return NULL; 78 83 } 79 // Allocate memory using psAlloc function - nChar bytes 84 80 85 // Copy input string to memory allocated up to nChar characters 81 // Return the copy 82 // Pass through NULL values 83 returnValue = 84 string ? strncpy(psAlloc((size_t) nChar + 1), string, (size_t) nChar) 85 : NULL; 86 psString output = psStringAlloc((size_t) nChar + 1); 87 output = strncpy(output, string, (size_t) nChar); 86 88 87 89 // Ensure the last byte is NULL character 88 returnValue[nChar] = '\0';90 output[nChar] = '\0'; 89 91 90 92 // Return the string pointer 91 return returnValue;93 return output; 92 94 } 93 95 … … 279 281 280 282 // this is safe since we will subtract strlen(key) elements from input 281 psString output = ps Alloc(strlen(input) + replaceLength + 1); // Output string283 psString output = psStringAlloc(strlen(input) + replaceLength + 1); // Output string 282 284 int Nc = p - input; // Number of characters to copy 283 285
Note:
See TracChangeset
for help on using the changeset viewer.
