Changeset 102207 in vbox for trunk/src/libs/xpcom18a4/nsprpub
- Timestamp:
- Nov 21, 2023 1:46:00 PM (14 months ago)
- Location:
- trunk/src/libs/xpcom18a4/nsprpub/pr
- Files:
-
- 4 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/nsprpub/pr/include/prerror.h
r11551 r102207 43 43 #ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP 44 44 #define PR_SetError VBoxNsprPR_SetError 45 #define PR_SetErrorText VBoxNsprPR_SetErrorText46 #define PR_GetError VBoxNsprPR_GetError47 #define PR_GetOSError VBoxNsprPR_GetOSError48 #define PR_GetErrorTextLength VBoxNsprPR_GetErrorTextLength49 #define PR_GetErrorText VBoxNsprPR_GetErrorText50 #define PR_ErrorToString VBoxNsprPR_ErrorToString51 #define PR_ErrorToName VBoxNsprPR_ErrorToName52 #define PR_ErrorLanguages VBoxNsprPR_ErrorLanguages53 #define PR_ErrorInstallTable VBoxNsprPR_ErrorInstallTable54 #define PR_ErrorInstallCallback VBoxNsprPR_ErrorInstallCallback55 45 #endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */ 56 46 PR_BEGIN_EXTERN_C … … 70 60 NSPR_API(void) PR_SetError(PRErrorCode errorCode, PRInt32 oserr); 71 61 72 /*73 ** The text value specified may be NULL. If it is not NULL and the text length74 ** is zero, the string is assumed to be a null terminated C string. Otherwise75 ** the text is assumed to be the length specified and possibly include NULL76 ** characters (e.g., a multi-national string).77 **78 ** The text will be copied into to thread structure and remain there79 ** until the next call to PR_SetError.80 */81 NSPR_API(void) PR_SetErrorText(82 PRIntn textLength, const char *text);83 84 /*85 ** Return the current threads last set error code.86 */87 NSPR_API(PRErrorCode) PR_GetError(void);88 89 /*90 ** Return the current threads last set os error code. This is used for91 ** machine specific code that desires the underlying os error.92 */93 NSPR_API(PRInt32) PR_GetOSError(void);94 95 /*96 ** Get the length of the error text. If a zero is returned, then there97 ** is no text. Otherwise, the value returned is sufficient to contain98 ** the error text currently available.99 */100 NSPR_API(PRInt32) PR_GetErrorTextLength(void);101 102 /*103 ** Copy the current threads current error text. Then actual number of bytes104 ** copied is returned as the result. If the result is zero, the 'text' area105 ** is unaffected.106 */107 NSPR_API(PRInt32) PR_GetErrorText(char *text);108 109 110 /*111 Copyright (C) 1987, 1988 Student Information Processing Board of the112 Massachusetts Institute of Technology.113 114 Permission to use, copy, modify, and distribute this software and its115 documentation for any purpose and without fee is hereby granted, provided116 that the above copyright notice appear in all copies and that both that117 copyright notice and this permission notice appear in supporting118 documentation, and that the names of M.I.T. and the M.I.T. S.I.P.B. not be119 used in advertising or publicity pertaining to distribution of the software120 without specific, written prior permission. M.I.T. and the M.I.T. S.I.P.B.121 make no representations about the suitability of this software for any122 purpose. It is provided "as is" without express or implied warranty.123 */124 125 126 /*127 * NOTE:128 * The interfaces for error-code-translation described in the rest of129 * this file are preliminary in the 3.1 release of nspr and are subject130 * to change in future releases.131 */132 133 /*134 ** Description: Localizable error code to string function.135 **136 **137 ** NSPR provides a mechanism for converting an error code to a138 ** descriptive string, in a caller-specified language.139 **140 ** Error codes themselves are 32 bit (signed) integers. Typically,141 ** the high order 24 bits are an identifier of which error table the142 ** error code is from, and the low order 8 bits are a sequential error143 ** number within the table. NSPR supports error tables whose first144 ** error code is not a multiple of 256, such error code assignments145 ** should be avoided when possible.146 **147 ** Error table 0 is defined to match the UNIX system call error table148 ** (sys_errlist); this allows errno values to be used directly in the149 ** library. Other error table numbers are typically formed by150 ** compacting together the first four characters of the error table151 ** name. The mapping between characters in the name and numeric152 ** values in the error code are defined in a system-independent153 ** fashion, so that two systems that can pass integral values between154 ** them can reliably pass error codes without loss of meaning; this155 ** should work even if the character sets used are not the156 ** same. (However, if this is to be done, error table 0 should be157 ** avoided, since the local system call error tables may differ.)158 **159 ** Libraries defining error codes need only provide a table mapping160 ** error code numbers to names and default English descriptions,161 ** calling a routine to install the table, making it ``known'' to NSPR162 ** library. Once installed, a table may not be removed. Any error163 ** code the library generates can be converted to the corresponding164 ** error message. There is also a default format for error codes165 ** accidentally returned before making the table known, which is of166 ** the form "unknown code foo 32", where "foo" would be the name of167 ** the table.168 **169 ** Normally, the error code conversion routine only supports the170 ** languages "i-default" and "en", returning the error-table-provided171 ** English description for both languages. The application may172 ** provide a localization plugin, allowing support for additional173 ** languages.174 **175 **/176 177 /**********************************************************************/178 /************************* TYPES AND CONSTANTS ************************/179 /**********************************************************************/180 181 /*182 * PRLanguageCode --183 *184 * NSPR represents a language code as a non-negative integer.185 * Languages 0 is always "i-default" the language you get without186 * explicit negotiation. Language 1 is always "en", English187 * which has been explicitly negotiated. Additional language188 * codes are defined by an application-provided localization plugin.189 */190 typedef PRUint32 PRLanguageCode;191 #define PR_LANGUAGE_I_DEFAULT 0 /* i-default, the default language */192 #define PR_LANGUAGE_EN 1 /* English, explicitly negotiated */193 194 /*195 * struct PRErrorMessage --196 *197 * An error message in an error table.198 */199 struct PRErrorMessage {200 const char * name; /* Macro name for error */201 const char * en_text; /* Default English text */202 };203 204 /*205 * struct PRErrorTable --206 *207 * An error table, provided by a library.208 */209 struct PRErrorTable {210 const struct PRErrorMessage * msgs; /* Array of error information */211 const char *name; /* Name of error table source */212 PRErrorCode base; /* Error code for first error in table */213 int n_msgs; /* Number of codes in table */214 };215 216 /*217 * struct PRErrorCallbackPrivate --218 *219 * A private structure for the localization plugin220 */221 struct PRErrorCallbackPrivate;222 223 /*224 * struct PRErrorCallbackTablePrivate --225 *226 * A data structure under which the localization plugin may store information,227 * associated with an error table, that is private to itself.228 */229 struct PRErrorCallbackTablePrivate;230 231 /*232 * PRErrorCallbackLookupFn --233 *234 * A function of PRErrorCallbackLookupFn type is a localization235 * plugin callback which converts an error code into a description236 * in the requested language. The callback is provided the237 * appropriate error table, private data for the plugin and the table.238 * The callback returns the appropriate UTF-8 encoded description, or NULL239 * if no description can be found.240 */241 typedef const char *242 PRErrorCallbackLookupFn(PRErrorCode code, PRLanguageCode language,243 const struct PRErrorTable *table,244 struct PRErrorCallbackPrivate *cb_private,245 struct PRErrorCallbackTablePrivate *table_private);246 247 /*248 * PRErrorCallbackNewTableFn --249 *250 * A function PRErrorCallbackNewTableFn type is a localization plugin251 * callback which is called once with each error table registered252 * with NSPR. The callback is provided with the error table and253 * the plugin's private structure. The callback returns any table private254 * data it wishes to associate with the error table. Does not need to be thread255 * safe.256 */257 typedef struct PRErrorCallbackTablePrivate *258 PRErrorCallbackNewTableFn(const struct PRErrorTable *table,259 struct PRErrorCallbackPrivate *cb_private);260 261 /**********************************************************************/262 /****************************** FUNCTIONS *****************************/263 /**********************************************************************/264 265 /***********************************************************************266 ** FUNCTION: PR_ErrorToString267 ** DESCRIPTION:268 ** Returns the UTF-8 message for an error code in269 ** the requested language. May return the message270 ** in the default language if a translation in the requested271 ** language is not available. The returned string is272 ** valid for the duration of the process. Never returns NULL.273 **274 ***********************************************************************/275 NSPR_API(const char *) PR_ErrorToString(PRErrorCode code,276 PRLanguageCode language);277 278 279 /***********************************************************************280 ** FUNCTION: PR_ErrorToName281 ** DESCRIPTION:282 ** Returns the macro name for an error code, or NULL283 ** if the error code is not known. The returned string is284 ** valid for the duration of the process.285 **286 ** Does not work for error table 0, the system error codes.287 **288 ***********************************************************************/289 NSPR_API(const char *) PR_ErrorToName(PRErrorCode code);290 291 292 /***********************************************************************293 ** FUNCTION: PR_ErrorLanguages294 ** DESCRIPTION:295 ** Returns the RFC 1766 language tags for the language296 ** codes PR_ErrorToString() supports. The returned array is valid297 ** for the duration of the process. Never returns NULL. The first298 ** item in the returned array is the language tag for PRLanguageCode 0,299 ** the second is for PRLanguageCode 1, and so on. The array is terminated300 ** with a null pointer.301 **302 ***********************************************************************/303 NSPR_API(const char * const *) PR_ErrorLanguages(void);304 305 306 /***********************************************************************307 ** FUNCTION: PR_ErrorInstallTable308 ** DESCRIPTION:309 ** Registers an error table with NSPR. Must be done exactly once per310 ** table. Memory pointed to by `table' must remain valid for the life311 ** of the process.312 **313 ** NOT THREAD SAFE!314 **315 ***********************************************************************/316 NSPR_API(PRErrorCode) PR_ErrorInstallTable(const struct PRErrorTable *table);317 318 319 /***********************************************************************320 ** FUNCTION: PR_ErrorInstallCallback321 ** DESCRIPTION:322 ** Registers an error localization plugin with NSPR. May be called323 ** at most one time. `languages' contains the language codes supported324 ** by this plugin. Languages 0 and 1 must be "i-default" and "en"325 ** respectively. `lookup' and `newtable' contain pointers to326 ** the plugin callback functions. `cb_private' contains any information327 ** private to the plugin functions.328 **329 ** NOT THREAD SAFE!330 **331 ***********************************************************************/332 NSPR_API(void) PR_ErrorInstallCallback(const char * const * languages,333 PRErrorCallbackLookupFn *lookup,334 PRErrorCallbackNewTableFn *newtable,335 struct PRErrorCallbackPrivate *cb_private);336 337 62 PR_END_EXTERN_C 338 63 -
trunk/src/libs/xpcom18a4/nsprpub/pr/src/misc/prerror.c
r1 r102207 38 38 #include "primpl.h" 39 39 40 #include <string.h>41 #include <stdlib.h>42 43 PR_IMPLEMENT(PRErrorCode) PR_GetError(void)44 {45 PRThread *thread = PR_GetCurrentThread();46 return thread->errorCode;47 }48 49 PR_IMPLEMENT(PRInt32) PR_GetOSError(void)50 {51 PRThread *thread = PR_GetCurrentThread();52 return thread->osErrorCode;53 }54 55 40 PR_IMPLEMENT(void) PR_SetError(PRErrorCode code, PRInt32 osErr) 56 41 { … … 60 45 thread->errorStringLength = 0; 61 46 } 62 63 PR_IMPLEMENT(void) PR_SetErrorText(PRIntn textLength, const char *text)64 {65 PRThread *thread = PR_GetCurrentThread();66 67 if (0 == textLength)68 {69 if (NULL != thread->errorString)70 PR_DELETE(thread->errorString);71 thread->errorStringSize = 0;72 }73 else74 {75 PRIntn size = textLength + 31; /* actual length to allocate. Plus a little extra */76 if (thread->errorStringSize < textLength+1) /* do we have room? */77 {78 if (NULL != thread->errorString)79 PR_DELETE(thread->errorString);80 thread->errorString = (char*)PR_MALLOC(size);81 if ( NULL == thread->errorString ) {82 thread->errorStringSize = 0;83 thread->errorStringLength = 0;84 return;85 }86 thread->errorStringSize = size;87 }88 memcpy(thread->errorString, text, textLength+1 );89 }90 thread->errorStringLength = textLength;91 }92 93 PR_IMPLEMENT(PRInt32) PR_GetErrorTextLength(void)94 {95 PRThread *thread = PR_GetCurrentThread();96 return thread->errorStringLength;97 } /* PR_GetErrorTextLength */98 99 PR_IMPLEMENT(PRInt32) PR_GetErrorText(char *text)100 {101 PRThread *thread = PR_GetCurrentThread();102 if (0 != thread->errorStringLength)103 memcpy(text, thread->errorString, thread->errorStringLength+1);104 return thread->errorStringLength;105 } /* PR_GetErrorText */106 107 -
trunk/src/libs/xpcom18a4/nsprpub/pr/src/misc/prinit.c
r102203 r102207 78 78 _PR_InitThreads(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); 79 79 80 nspr_InitializePRErrorTable();81 82 80 _PR_MD_FINAL_INIT(); 83 81 }
Note:
See TracChangeset
for help on using the changeset viewer.