Changeset 2129 for trunk/psLib/src/sysUtils/psErrorCodes.c
- Timestamp:
- Oct 14, 2004, 11:14:58 AM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sysUtils/psErrorCodes.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sysUtils/psErrorCodes.c
r1905 r2129 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 9$ $Name: not supported by cvs2svn $10 * @date $Date: 2004- 09-27 20:38:02$9 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-10-14 21:14:58 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 13 13 */ 14 15 #include <string.h> 14 16 15 17 #include "psError.h" … … 75 77 desc = (psErrorDescription*)psListGet(dynamicErrorCodes,PS_LIST_HEAD); 76 78 while (desc != NULL) { 77 desc = (psErrorDescription*)psListGetNext(dynamicErrorCodes); 78 if (desc != NULL && desc->code == code) { 79 if (desc->code == code) { 79 80 return desc; 80 81 } 82 desc = (psErrorDescription*)psListGetNext(dynamicErrorCodes); 81 83 } 82 84 } 83 85 return NULL; 84 86 } 87 88 static void freeErrorDescription(psErrorDescription* err) 89 { 90 psFree((void*)err->description); 91 } 92 93 psErrorDescription* psErrorDescriptionAlloc(psErrorCode code, 94 const char *description) 95 { 96 psErrorDescription* err = psAlloc(sizeof(psErrorDescription)); 97 err->code = code; 98 if (description == NULL) { 99 err->description = NULL; 100 } else { 101 err->description = psAlloc(sizeof(char)*strlen(description)+1); 102 strcpy((char*)err->description,description); 103 } 104 105 p_psMemSetDeallocator(err,(psFreeFcn)freeErrorDescription); 106 return err; 107 } 108 85 109 86 110 const char *psErrorCodeString(psErrorCode code) … … 114 138 } 115 139 140 if (dynamicErrorCodes == NULL) { 141 dynamicErrorCodes = psListAlloc(NULL); 142 p_psMemSetPersistent(dynamicErrorCodes,true); 143 } 144 116 145 for (int i=0;i<nerror;i++) { 146 psErrorDescription* err = psErrorDescriptionAlloc( 147 errors[i].code, errors[i].description); 148 p_psMemSetPersistent(err,true); 149 p_psMemSetPersistent((void*)err->description,true); 117 150 if (! psListAdd(dynamicErrorCodes, 118 151 PS_LIST_HEAD, 119 (void*)&errors[i]) ) {152 err) ) { 120 153 121 154 psErrorMsg(PS_ERRORNAME_DOMAIN "psErrorRegister", … … 124 157 i); 125 158 } 159 p_psMemSetPersistent(dynamicErrorCodes->head,true); 160 psFree(err); 126 161 } 127 162 } 128 163 164 bool p_psErrorUnregister(psErrorCode code) 165 { 166 // Check input argument is non-negative 167 if ( code < 0 ) { 168 return false; 169 } 170 171 const psErrorDescription* desc = getErrorDescription(code); 172 173 if (desc == NULL) { 174 return false; 175 } 176 177 if (dynamicErrorCodes == NULL) { 178 return false; 179 } 180 181 return psListRemove(dynamicErrorCodes,PS_LIST_UNKNOWN,(void*)desc); 182 }
Note:
See TracChangeset
for help on using the changeset viewer.
