Changeset 1407 for trunk/psLib/src/sysUtils/psString.c
- Timestamp:
- Aug 6, 2004, 2:06:06 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sysUtils/psString.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sysUtils/psString.c
r1406 r1407 1 1 2 /** @file psString.c 2 3 * … … 8 9 * @author Eric Van Alst, MHPCC 9 10 * 10 * @version $Revision: 1. 7$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-08-0 6 22:34:05$11 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-08-07 00:06:06 $ 12 13 * 13 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 15 16 16 17 /******************************************************************************/ 18 17 19 /* INCLUDE FILES */ 20 18 21 /******************************************************************************/ 19 22 #include <stdlib.h> … … 24 27 25 28 /******************************************************************************/ 29 26 30 /* DEFINE STATEMENTS */ 31 27 32 /******************************************************************************/ 28 33 … … 30 35 31 36 /******************************************************************************/ 37 32 38 /* TYPE DEFINITIONS */ 39 33 40 /******************************************************************************/ 34 41 … … 36 43 37 44 /*****************************************************************************/ 45 38 46 /* GLOBAL VARIABLES */ 47 39 48 /*****************************************************************************/ 40 49 … … 42 51 43 52 /*****************************************************************************/ 53 44 54 /* FILE STATIC VARIABLES */ 55 45 56 /*****************************************************************************/ 46 57 … … 48 59 49 60 /*****************************************************************************/ 61 50 62 /* FUNCTION IMPLEMENTATION - LOCAL */ 63 51 64 /*****************************************************************************/ 52 65 … … 54 67 55 68 /*****************************************************************************/ 69 56 70 /* FUNCTION IMPLEMENTATION - PUBLIC */ 71 57 72 /*****************************************************************************/ 58 73 59 char *psStringCopy( 60 const char* str 61 ) 74 char *psStringCopy(const char *str) 62 75 { 63 76 // Allocate memory using psAlloc function … … 67 80 } 68 81 69 char *psStringNCopy( 70 const char* str, 71 int nChar 72 ) 82 char *psStringNCopy(const char *str, int nChar) 73 83 { 74 84 char *returnValue = NULL; 75 85 76 86 // Check the number of characters to copy is non-negative 77 if ( nChar < 0) {87 if (nChar < 0) { 78 88 // Log error message and return NULL 79 psError(__FILE__,"psStringNCopy with negative count specified %d", 80 nChar); 89 psError(__FILE__, "psStringNCopy with negative count specified %d", nChar); 81 90 return NULL; 82 91 } … … 84 93 // Copy input string to memory allocated up to nChar characters 85 94 // Return the copy 86 returnValue = strncpy(psAlloc((size_t) nChar + 1), str, (size_t)nChar);95 returnValue = strncpy(psAlloc((size_t) nChar + 1), str, (size_t) nChar); 87 96 88 97 // Ensure the last byte is NULL character 89 if ( nChar > 0) {90 returnValue[nChar -1] = '\0';98 if (nChar > 0) { 99 returnValue[nChar - 1] = '\0'; 91 100 } 92 93 101 // Return the string pointer 94 102 return returnValue; 95 103 } 96 97
Note:
See TracChangeset
for help on using the changeset viewer.
