Error.c revision 0568f49b
1444c061aSmrg/*********************************************************** 2249c3046SmrgCopyright (c) 1993, Oracle and/or its affiliates. All rights reserved. 31477040fSmrg 41477040fSmrgPermission is hereby granted, free of charge, to any person obtaining a 51477040fSmrgcopy of this software and associated documentation files (the "Software"), 61477040fSmrgto deal in the Software without restriction, including without limitation 71477040fSmrgthe rights to use, copy, modify, merge, publish, distribute, sublicense, 81477040fSmrgand/or sell copies of the Software, and to permit persons to whom the 91477040fSmrgSoftware is furnished to do so, subject to the following conditions: 101477040fSmrg 111477040fSmrgThe above copyright notice and this permission notice (including the next 121477040fSmrgparagraph) shall be included in all copies or substantial portions of the 131477040fSmrgSoftware. 141477040fSmrg 151477040fSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 161477040fSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 171477040fSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 181477040fSmrgTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 191477040fSmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 201477040fSmrgFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 211477040fSmrgDEALINGS IN THE SOFTWARE. 221477040fSmrg 231477040fSmrgCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts. 24444c061aSmrg 25444c061aSmrg All Rights Reserved 26444c061aSmrg 27444c061aSmrgPermission to use, copy, modify, and distribute this software and its 28444c061aSmrgdocumentation for any purpose and without fee is hereby granted, 29444c061aSmrgprovided that the above copyright notice appear in all copies and that 30444c061aSmrgboth that copyright notice and this permission notice appear in 311477040fSmrgsupporting documentation, and that the name of Digital not be 32444c061aSmrgused in advertising or publicity pertaining to distribution of the 33444c061aSmrgsoftware without specific, written prior permission. 34444c061aSmrg 35444c061aSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 36444c061aSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 37444c061aSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 38444c061aSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 39444c061aSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 40444c061aSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 41444c061aSmrgSOFTWARE. 42444c061aSmrg 43444c061aSmrg******************************************************************/ 44444c061aSmrg 45444c061aSmrg/* 46444c061aSmrg 47444c061aSmrgCopyright 1987, 1988, 1998 The Open Group 48444c061aSmrg 49444c061aSmrgPermission to use, copy, modify, distribute, and sell this software and its 50444c061aSmrgdocumentation for any purpose is hereby granted without fee, provided that 51444c061aSmrgthe above copyright notice appear in all copies and that both that 52444c061aSmrgcopyright notice and this permission notice appear in supporting 53444c061aSmrgdocumentation. 54444c061aSmrg 55444c061aSmrgThe above copyright notice and this permission notice shall be included in 56444c061aSmrgall copies or substantial portions of the Software. 57444c061aSmrg 58444c061aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 59444c061aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 60444c061aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 61444c061aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 62444c061aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 63444c061aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 64444c061aSmrg 65444c061aSmrgExcept as contained in this notice, the name of The Open Group shall not be 66444c061aSmrgused in advertising or otherwise to promote the sale, use or other dealings 67444c061aSmrgin this Software without prior written authorization from The Open Group. 68444c061aSmrg 69444c061aSmrg*/ 70444c061aSmrg 71444c061aSmrg#ifdef HAVE_CONFIG_H 72444c061aSmrg#include <config.h> 73444c061aSmrg#endif 74444c061aSmrg#include "IntrinsicI.h" 75444c061aSmrg#include <stdio.h> 76444c061aSmrg#include <stdlib.h> 77444c061aSmrg 78444c061aSmrg/* The error handlers in the application context aren't used since we can't 79444c061aSmrg come up with a uniform way of using them. If you can, define 80444c061aSmrg GLOBALERRORS to be FALSE (or 0). */ 81444c061aSmrg 82444c061aSmrg#ifndef GLOBALERRORS 83444c061aSmrg#define GLOBALERRORS 1 84444c061aSmrg#endif 85444c061aSmrg 86444c061aSmrgstatic void InitErrorHandling(XrmDatabase *); 87444c061aSmrg#if GLOBALERRORS 88444c061aSmrgstatic XrmDatabase errorDB = NULL; 89444c061aSmrgstatic Boolean error_inited = FALSE; 90444c061aSmrgvoid _XtDefaultErrorMsg(String, String, String, String, String*, Cardinal*); 91444c061aSmrgvoid _XtDefaultWarningMsg(String, String, String, String, String*, Cardinal*); 92339a7c43Smrgvoid _XtDefaultError(String) _X_NORETURN; 93444c061aSmrgvoid _XtDefaultWarning(String); 94444c061aSmrgstatic XtErrorMsgHandler errorMsgHandler = _XtDefaultErrorMsg; 95444c061aSmrgstatic XtErrorMsgHandler warningMsgHandler = _XtDefaultWarningMsg; 960568f49bSmrgstatic XtErrorHandler errorHandler _X_NORETURN = _XtDefaultError; 97444c061aSmrgstatic XtErrorHandler warningHandler = _XtDefaultWarning; 98444c061aSmrg#endif /* GLOBALERRORS */ 99444c061aSmrg 100444c061aSmrgXrmDatabase *XtGetErrorDatabase(void) 101444c061aSmrg{ 102444c061aSmrg XrmDatabase* retval; 103444c061aSmrg#if GLOBALERRORS 104444c061aSmrg LOCK_PROCESS; 105444c061aSmrg retval = &errorDB; 106444c061aSmrg UNLOCK_PROCESS; 107444c061aSmrg#else 108444c061aSmrg retval = XtAppGetErrorDatabase(_XtDefaultAppContext()); 109444c061aSmrg#endif /* GLOBALERRORS */ 110444c061aSmrg return retval; 111444c061aSmrg} 112444c061aSmrg 113444c061aSmrgXrmDatabase *XtAppGetErrorDatabase( 114444c061aSmrg XtAppContext app) 115444c061aSmrg{ 116444c061aSmrg XrmDatabase* retval; 117444c061aSmrg#if GLOBALERRORS 118444c061aSmrg LOCK_PROCESS; 119444c061aSmrg retval = &errorDB; 120444c061aSmrg UNLOCK_PROCESS; 121444c061aSmrg#else 122444c061aSmrg LOCK_APP(app); 123444c061aSmrg retval= &app->errorDB; 124444c061aSmrg UNLOCK_APP(app); 125444c061aSmrg#endif /* GLOBALERRORS */ 126444c061aSmrg return retval; 127444c061aSmrg} 128444c061aSmrg 129444c061aSmrgvoid XtGetErrorDatabaseText( 130444c061aSmrg register _Xconst char* name, 131444c061aSmrg register _Xconst char* type, 132444c061aSmrg register _Xconst char* class, 133444c061aSmrg _Xconst char* defaultp, 1340568f49bSmrg _XtString buffer, 135444c061aSmrg int nbytes) 136444c061aSmrg{ 137444c061aSmrg#if GLOBALERRORS 138444c061aSmrg XtAppGetErrorDatabaseText(NULL, 139444c061aSmrg name,type,class,defaultp, buffer, nbytes, NULL); 140444c061aSmrg#else 141444c061aSmrg XtAppGetErrorDatabaseText(_XtDefaultAppContext(), 142444c061aSmrg name,type,class,defaultp, buffer, nbytes, NULL); 143444c061aSmrg#endif /* GLOBALERRORS */ 144444c061aSmrg} 145444c061aSmrg 146444c061aSmrgvoid XtAppGetErrorDatabaseText( 147444c061aSmrg XtAppContext app, 148444c061aSmrg register _Xconst char* name, 149444c061aSmrg register _Xconst char* type, 150444c061aSmrg register _Xconst char* class, 151444c061aSmrg _Xconst char* defaultp, 1520568f49bSmrg _XtString buffer, 153444c061aSmrg int nbytes, 154444c061aSmrg XrmDatabase db) 155444c061aSmrg{ 156444c061aSmrg String str_class; 1570568f49bSmrg _XtString type_str; 158444c061aSmrg XrmValue result; 159444c061aSmrg char *str_name = NULL; 160444c061aSmrg char *temp = NULL; 161444c061aSmrg 162444c061aSmrg#if GLOBALERRORS 163444c061aSmrg LOCK_PROCESS; 164444c061aSmrg if (error_inited == FALSE) { 165444c061aSmrg InitErrorHandling (&errorDB); 166444c061aSmrg error_inited = TRUE; 167444c061aSmrg } 168444c061aSmrg#else 169444c061aSmrg LOCK_APP(app); 170444c061aSmrg if (app->error_inited == FALSE) { 171444c061aSmrg InitErrorHandling (&app->errorDB); 172444c061aSmrg app->error_inited = TRUE; 173444c061aSmrg } 174444c061aSmrg#endif /* GLOBALERRORS */ 175444c061aSmrg if (!(str_name = ALLOCATE_LOCAL(strlen(name) + strlen(type) + 2))) 176444c061aSmrg _XtAllocError(NULL); 177444c061aSmrg (void) sprintf(str_name, "%s.%s", name, type); 178444c061aSmrg /* XrmGetResource requires the name and class to be fully qualified 179444c061aSmrg * and to have the same number of components. */ 180444c061aSmrg str_class = (char *)class; 181444c061aSmrg if (! strchr(class, '.')) { 182444c061aSmrg if (!(temp = ALLOCATE_LOCAL(2 * strlen(class) + 2))) 183444c061aSmrg _XtAllocError(NULL); 184444c061aSmrg (void) sprintf(temp, "%s.%s", class, class); 185444c061aSmrg str_class = temp; 186444c061aSmrg } 187444c061aSmrg if (db == NULL) { 188444c061aSmrg#if GLOBALERRORS 189444c061aSmrg (void) XrmGetResource(errorDB, str_name, str_class, &type_str, 190444c061aSmrg &result); 191444c061aSmrg#else 192444c061aSmrg (void) XrmGetResource(app->errorDB, str_name, str_class, &type_str, 193444c061aSmrg &result); 194444c061aSmrg#endif /* GLOBALERRORS */ 195444c061aSmrg } else (void) XrmGetResource(db, str_name, str_class, &type_str, &result); 196444c061aSmrg if (result.addr) { 1970568f49bSmrg (void) strncpy (buffer, result.addr, (size_t) nbytes); 198444c061aSmrg if (result.size > (unsigned) nbytes) buffer[nbytes-1] = 0; 199444c061aSmrg } else { 2000568f49bSmrg int len = (int) strlen(defaultp); 201444c061aSmrg if (len >= nbytes) len = nbytes-1; 2020568f49bSmrg (void) memmove(buffer, defaultp, (size_t) len); 203444c061aSmrg buffer[len] = '\0'; 204444c061aSmrg } 205444c061aSmrg if (str_name) 206444c061aSmrg DEALLOCATE_LOCAL(str_name); 207444c061aSmrg if (temp) 208444c061aSmrg DEALLOCATE_LOCAL(temp); 209444c061aSmrg#if GLOBALERRORS 210444c061aSmrg UNLOCK_PROCESS; 211444c061aSmrg#else 212444c061aSmrg UNLOCK_APP(app); 213444c061aSmrg#endif 214444c061aSmrg} 215444c061aSmrg 216444c061aSmrgstatic void InitErrorHandling ( 217444c061aSmrg XrmDatabase *db) 218444c061aSmrg{ 219444c061aSmrg XrmDatabase errordb; 220444c061aSmrg 221444c061aSmrg errordb = XrmGetFileDatabase(ERRORDB); 222444c061aSmrg XrmMergeDatabases(errordb, db); 223444c061aSmrg} 224444c061aSmrg 225444c061aSmrgstatic void DefaultMsg ( 226444c061aSmrg String name, 227444c061aSmrg String type, 228444c061aSmrg String class, 229444c061aSmrg String defaultp, 230444c061aSmrg String* params, 231444c061aSmrg Cardinal* num_params, 232444c061aSmrg Bool error, 233444c061aSmrg void (*fn)(_Xconst _XtString)) 234444c061aSmrg{ 235444c061aSmrg#define BIGBUF 1024 236444c061aSmrg char buffer[BIGBUF]; 237444c061aSmrg char* message; 238444c061aSmrg XtGetErrorDatabaseText(name,type,class,defaultp, buffer, BIGBUF); 239444c061aSmrg/*need better solution here, perhaps use lower level printf primitives? */ 240444c061aSmrg if (params == NULL || num_params == NULL || *num_params == 0) 241444c061aSmrg (*fn)(buffer); 242444c061aSmrg#ifndef WIN32 /* and OS/2 */ 243444c061aSmrg else if ((getuid () != geteuid ()) || getuid() == 0) { 244444c061aSmrg if ((error && errorHandler == _XtDefaultError) || 245444c061aSmrg (!error && warningHandler == _XtDefaultWarning)) { 246444c061aSmrg /* 247444c061aSmrg * if it's just going to go to stderr anyway, then we'll 248444c061aSmrg * fprintf to stderr ourselves and skip the insecure sprintf. 249444c061aSmrg */ 250444c061aSmrg Cardinal i = *num_params; 251444c061aSmrg String par[10]; 252444c061aSmrg if (i > 10) i = 10; 253444c061aSmrg (void) memmove((char*)par, (char*)params, i * sizeof(String) ); 2540568f49bSmrg memset( &par[i], 0, (10-i) * sizeof(String) ); 255444c061aSmrg (void) fprintf (stderr, "%s%s", 256444c061aSmrg error ? XTERROR_PREFIX : XTWARNING_PREFIX, 257444c061aSmrg error ? "Error: " : "Warning: "); 258444c061aSmrg (void) fprintf (stderr, buffer, 259444c061aSmrg par[0], par[1], par[2], par[3], par[4], 260444c061aSmrg par[5], par[6], par[7], par[8], par[9]); 261444c061aSmrg (void) fprintf (stderr, "%c", '\n'); 262444c061aSmrg if (i != *num_params) 263444c061aSmrg (*fn) ( "Some arguments in previous message were lost" ); 264444c061aSmrg else if (error) exit (1); 265444c061aSmrg } else { 266444c061aSmrg /* 267444c061aSmrg * can't tell what it might do, so we'll play it safe 268444c061aSmrg */ 269444c061aSmrg XtWarning ("\ 270444c061aSmrgThis program is an suid-root program or is being run by the root user.\n\ 271444c061aSmrgThe full text of the error or warning message cannot be safely formatted\n\ 272444c061aSmrgin this environment. You may get a more descriptive message by running the\n\ 273444c061aSmrgprogram as a non-root user or by removing the suid bit on the executable."); 274444c061aSmrg (*fn)(buffer); /* if *fn is an ErrorHandler it should exit */ 275444c061aSmrg } 276444c061aSmrg } 277444c061aSmrg#endif 278444c061aSmrg else { 279444c061aSmrg /* 280444c061aSmrg * If you have snprintf the worst thing that could happen is you'd 281444c061aSmrg * lose some information. Without snprintf you're probably going to 282444c061aSmrg * scramble your heap and perhaps SEGV -- sooner or later. 283444c061aSmrg * If it hurts when you go like this then don't go like this! :-) 284444c061aSmrg */ 285444c061aSmrg Cardinal i = *num_params; 286444c061aSmrg String par[10]; 287444c061aSmrg if (i > 10) i = 10; 288444c061aSmrg (void) memmove((char*)par, (char*)params, i * sizeof(String) ); 2890568f49bSmrg memset( &par[i], 0, (10-i) * sizeof(String) ); 290444c061aSmrg if (i != *num_params) 291444c061aSmrg XtWarning( "Some arguments in following message were lost" ); 292444c061aSmrg /* 293444c061aSmrg * resist any temptation you might have to make `message' a 294444c061aSmrg * local buffer on the stack. Doing so is a security hole 295444c061aSmrg * in programs executing as root. Error and Warning 296444c061aSmrg * messages shouldn't be called frequently enough for this 297444c061aSmrg * to be a performance issue. 298444c061aSmrg */ 299444c061aSmrg if ((message = __XtMalloc (BIGBUF))) { 300444c061aSmrg (void) snprintf (message, BIGBUF, buffer, 301bdf0f55dSmrg par[0], par[1], par[2], par[3], par[4], 302bdf0f55dSmrg par[5], par[6], par[7], par[8], par[9]); 303444c061aSmrg (*fn)(message); 304444c061aSmrg XtFree(message); 305444c061aSmrg } else { 306444c061aSmrg XtWarning ("Memory allocation failed, arguments in the following message were lost"); 307444c061aSmrg (*fn)(buffer); 308444c061aSmrg } 309444c061aSmrg } 310444c061aSmrg} 311444c061aSmrg 312444c061aSmrgvoid _XtDefaultErrorMsg ( 313444c061aSmrg String name, 314444c061aSmrg String type, 315444c061aSmrg String class, 316444c061aSmrg String defaultp, 317444c061aSmrg String* params, 318444c061aSmrg Cardinal* num_params) 319444c061aSmrg{ 320444c061aSmrg DefaultMsg (name,type,class,defaultp,params,num_params,True,XtError); 321444c061aSmrg} 322444c061aSmrg 323444c061aSmrgvoid _XtDefaultWarningMsg ( 324444c061aSmrg String name, 325444c061aSmrg String type, 326444c061aSmrg String class, 327444c061aSmrg String defaultp, 328444c061aSmrg String* params, 329444c061aSmrg Cardinal* num_params) 330444c061aSmrg{ 331444c061aSmrg DefaultMsg (name,type,class,defaultp,params,num_params,False,XtWarning); 332444c061aSmrg} 333444c061aSmrg 334444c061aSmrgvoid XtErrorMsg( 335444c061aSmrg _Xconst char* name, 336444c061aSmrg _Xconst char* type, 337444c061aSmrg _Xconst char* class, 338444c061aSmrg _Xconst char* defaultp, 339444c061aSmrg String* params, 340444c061aSmrg Cardinal* num_params) 341444c061aSmrg{ 342444c061aSmrg#if GLOBALERRORS 343444c061aSmrg LOCK_PROCESS; 344444c061aSmrg (*errorMsgHandler)((String)name,(String)type,(String)class, 345444c061aSmrg (String)defaultp,params,num_params); 346444c061aSmrg UNLOCK_PROCESS; 3470568f49bSmrg exit(1); 348444c061aSmrg#else 349444c061aSmrg XtAppErrorMsg(_XtDefaultAppContext(),name,type,class, 350444c061aSmrg defaultp,params,num_params); 351444c061aSmrg#endif /* GLOBALERRORS */ 352444c061aSmrg} 353444c061aSmrg 354444c061aSmrgvoid XtAppErrorMsg( 355444c061aSmrg XtAppContext app, 356444c061aSmrg _Xconst char* name, 357444c061aSmrg _Xconst char* type, 358444c061aSmrg _Xconst char* class, 359444c061aSmrg _Xconst char* defaultp, 360444c061aSmrg String* params, 361444c061aSmrg Cardinal* num_params) 362444c061aSmrg{ 363444c061aSmrg#if GLOBALERRORS 364444c061aSmrg LOCK_PROCESS; 365444c061aSmrg (*errorMsgHandler)((String)name,(String)type,(String)class, 366444c061aSmrg (String)defaultp,params,num_params); 367444c061aSmrg UNLOCK_PROCESS; 3680568f49bSmrg exit(1); 369444c061aSmrg#else 370444c061aSmrg LOCK_APP(app); 371444c061aSmrg (*app->errorMsgHandler)(name,type,class,defaultp,params,num_params); 372444c061aSmrg UNLOCK_APP(app); 373444c061aSmrg#endif /* GLOBALERRORS */ 374444c061aSmrg} 375444c061aSmrg 376444c061aSmrgvoid XtWarningMsg( 377444c061aSmrg _Xconst char* name, 378444c061aSmrg _Xconst char* type, 379444c061aSmrg _Xconst char* class, 380444c061aSmrg _Xconst char* defaultp, 381444c061aSmrg String* params, 382444c061aSmrg Cardinal* num_params) 383444c061aSmrg{ 384444c061aSmrg#if GLOBALERRORS 385444c061aSmrg LOCK_PROCESS; 386444c061aSmrg (*warningMsgHandler)((String)name,(String)type,(String)class, 387444c061aSmrg (String)defaultp,params,num_params); 388444c061aSmrg UNLOCK_PROCESS; 389444c061aSmrg#else 390444c061aSmrg XtAppWarningMsg(_XtDefaultAppContext(),name,type,class, 391444c061aSmrg defaultp,params,num_params); 392444c061aSmrg#endif /* GLOBALERRORS */ 393444c061aSmrg} 394444c061aSmrg 395444c061aSmrgvoid XtAppWarningMsg( 396444c061aSmrg XtAppContext app, 397444c061aSmrg _Xconst char* name, 398444c061aSmrg _Xconst char* type, 399444c061aSmrg _Xconst char* class, 400444c061aSmrg _Xconst char* defaultp, 401444c061aSmrg String* params, 402444c061aSmrg Cardinal* num_params) 403444c061aSmrg{ 404444c061aSmrg#if GLOBALERRORS 405444c061aSmrg LOCK_PROCESS; 406444c061aSmrg (*warningMsgHandler)((String)name,(String)type,(String)class, 407444c061aSmrg (String)defaultp,params,num_params); 408444c061aSmrg UNLOCK_PROCESS; 409444c061aSmrg#else 410444c061aSmrg LOCK_APP(app); 411444c061aSmrg (*app->warningMsgHandler)(name,type,class,defaultp,params,num_params); 412444c061aSmrg UNLOCK_APP(app); 413444c061aSmrg#endif /* GLOBALERRORS */ 414444c061aSmrg} 415444c061aSmrg 416444c061aSmrgvoid XtSetErrorMsgHandler( 4170568f49bSmrg XtErrorMsgHandler handler _X_NORETURN) 418444c061aSmrg{ 419444c061aSmrg#if GLOBALERRORS 420444c061aSmrg LOCK_PROCESS; 421444c061aSmrg if (handler != NULL) errorMsgHandler = handler; 422444c061aSmrg else errorMsgHandler = _XtDefaultErrorMsg; 423444c061aSmrg UNLOCK_PROCESS; 424444c061aSmrg#else 425444c061aSmrg XtAppSetErrorMsgHandler(_XtDefaultAppContext(), handler); 426444c061aSmrg#endif /* GLOBALERRORS */ 427444c061aSmrg} 428444c061aSmrg 429444c061aSmrgXtErrorMsgHandler XtAppSetErrorMsgHandler( 430444c061aSmrg XtAppContext app, 4310568f49bSmrg XtErrorMsgHandler handler _X_NORETURN) 432444c061aSmrg{ 433444c061aSmrg XtErrorMsgHandler old; 434444c061aSmrg#if GLOBALERRORS 435444c061aSmrg LOCK_PROCESS; 436444c061aSmrg old = errorMsgHandler; 437444c061aSmrg if (handler != NULL) errorMsgHandler = handler; 438444c061aSmrg else errorMsgHandler = _XtDefaultErrorMsg; 439444c061aSmrg UNLOCK_PROCESS; 440444c061aSmrg#else 441444c061aSmrg LOCK_APP(app); 442444c061aSmrg old = app->errorMsgHandler; 443444c061aSmrg if (handler != NULL) app->errorMsgHandler = handler; 444444c061aSmrg else app->errorMsgHandler = _XtDefaultErrorMsg; 445444c061aSmrg UNLOCK_APP(app); 446444c061aSmrg#endif /* GLOBALERRORS */ 447444c061aSmrg return old; 448444c061aSmrg} 449444c061aSmrg 450444c061aSmrgvoid XtSetWarningMsgHandler( 451444c061aSmrg XtErrorMsgHandler handler) 452444c061aSmrg{ 453444c061aSmrg#if GLOBALERRORS 454444c061aSmrg LOCK_PROCESS; 455444c061aSmrg if (handler != NULL) warningMsgHandler = handler; 456444c061aSmrg else warningMsgHandler = _XtDefaultWarningMsg; 457444c061aSmrg UNLOCK_PROCESS; 458444c061aSmrg#else 459444c061aSmrg XtAppSetWarningMsgHandler(_XtDefaultAppContext(),handler); 460444c061aSmrg#endif /* GLOBALERRORS */ 461444c061aSmrg} 462444c061aSmrg 463444c061aSmrgXtErrorMsgHandler XtAppSetWarningMsgHandler( 464444c061aSmrg XtAppContext app, 465444c061aSmrg XtErrorMsgHandler handler) 466444c061aSmrg{ 467444c061aSmrg XtErrorMsgHandler old; 468444c061aSmrg#if GLOBALERRORS 469444c061aSmrg LOCK_PROCESS; 470444c061aSmrg old = warningMsgHandler; 471444c061aSmrg if (handler != NULL) warningMsgHandler = handler; 472444c061aSmrg else warningMsgHandler = _XtDefaultWarningMsg; 473444c061aSmrg UNLOCK_PROCESS; 474444c061aSmrg#else 475444c061aSmrg LOCK_APP(app); 476444c061aSmrg old = app->warningMsgHandler; 477444c061aSmrg if (handler != NULL) app->warningMsgHandler = handler; 478444c061aSmrg else app->warningMsgHandler = _XtDefaultWarningMsg; 479444c061aSmrg UNLOCK_APP(app); 480444c061aSmrg#endif /* GLOBALERRORS */ 481444c061aSmrg return old; 482444c061aSmrg} 483444c061aSmrg 484444c061aSmrgvoid _XtDefaultError(String message) 485444c061aSmrg{ 486444c061aSmrg if (message && *message) 487444c061aSmrg (void)fprintf(stderr, "%sError: %s\n", XTERROR_PREFIX, message); 488444c061aSmrg exit(1); 489444c061aSmrg} 490444c061aSmrg 491444c061aSmrgvoid _XtDefaultWarning(String message) 492444c061aSmrg{ 493444c061aSmrg if (message && *message) 494444c061aSmrg (void)fprintf(stderr, "%sWarning: %s\n", XTWARNING_PREFIX, message); 495444c061aSmrg return; 496444c061aSmrg} 497444c061aSmrg 498444c061aSmrgvoid XtError( 499444c061aSmrg _Xconst char* message) 500444c061aSmrg{ 501444c061aSmrg#if GLOBALERRORS 502444c061aSmrg LOCK_PROCESS; 503444c061aSmrg (*errorHandler)((String)message); 504444c061aSmrg UNLOCK_PROCESS; 505444c061aSmrg#else 506444c061aSmrg XtAppError(_XtDefaultAppContext(),message); 507444c061aSmrg#endif /* GLOBALERRORS */ 508444c061aSmrg} 509444c061aSmrg 510444c061aSmrgvoid XtAppError( 511444c061aSmrg XtAppContext app, 512444c061aSmrg _Xconst char* message) 513444c061aSmrg{ 514444c061aSmrg#if GLOBALERRORS 515444c061aSmrg LOCK_PROCESS; 516444c061aSmrg (*errorHandler)((String)message); 517444c061aSmrg UNLOCK_PROCESS; 518444c061aSmrg#else 519444c061aSmrg LOCK_APP(app); 520444c061aSmrg (*app->errorHandler)(message); 521444c061aSmrg UNLOCK_APP(app); 522444c061aSmrg#endif /* GLOBALERRORS */ 523444c061aSmrg} 524444c061aSmrg 525444c061aSmrgvoid XtWarning( 526444c061aSmrg _Xconst char* message) 527444c061aSmrg{ 528444c061aSmrg#if GLOBALERRORS 529444c061aSmrg LOCK_PROCESS; 530444c061aSmrg (*warningHandler)((String)message); 531444c061aSmrg UNLOCK_PROCESS; 532444c061aSmrg#else 533444c061aSmrg XtAppWarning(_XtDefaultAppContext(),message); 534444c061aSmrg#endif /* GLOBALERRORS */ 535444c061aSmrg} 536444c061aSmrg 537444c061aSmrgvoid XtAppWarning( 538444c061aSmrg XtAppContext app, 539444c061aSmrg _Xconst char* message) 540444c061aSmrg{ 541444c061aSmrg#if GLOBALERRORS 542444c061aSmrg LOCK_PROCESS; 543444c061aSmrg (*warningHandler)((String)message); 544444c061aSmrg UNLOCK_PROCESS; 545444c061aSmrg#else 546444c061aSmrg LOCK_APP(app); 547444c061aSmrg (*app->warningHandler)(message); 548444c061aSmrg UNLOCK_APP(app); 549444c061aSmrg#endif /* GLOBALERRORS */ 550444c061aSmrg} 551444c061aSmrg 5520568f49bSmrgvoid XtSetErrorHandler(XtErrorHandler handler _X_NORETURN) 553444c061aSmrg{ 554444c061aSmrg#if GLOBALERRORS 555444c061aSmrg LOCK_PROCESS; 556444c061aSmrg if (handler != NULL) errorHandler = handler; 557444c061aSmrg else errorHandler = _XtDefaultError; 558444c061aSmrg UNLOCK_PROCESS; 559444c061aSmrg#else 560444c061aSmrg XtAppSetErrorHandler(_XtDefaultAppContext(),handler); 561444c061aSmrg#endif /* GLOBALERRORS */ 562444c061aSmrg} 563444c061aSmrg 564444c061aSmrgXtErrorHandler XtAppSetErrorHandler( 565444c061aSmrg XtAppContext app, 5660568f49bSmrg XtErrorHandler handler _X_NORETURN) 567444c061aSmrg{ 568444c061aSmrg XtErrorHandler old; 569444c061aSmrg#if GLOBALERRORS 570444c061aSmrg LOCK_PROCESS; 571444c061aSmrg old = errorHandler; 572444c061aSmrg if (handler != NULL) errorHandler = handler; 573444c061aSmrg else errorHandler = _XtDefaultError; 574444c061aSmrg UNLOCK_PROCESS; 575444c061aSmrg#else 576444c061aSmrg LOCK_APP(app); 577444c061aSmrg old = app->errorHandler; 578444c061aSmrg if (handler != NULL) app->errorHandler = handler; 579444c061aSmrg else app->errorHandler = _XtDefaultError; 580444c061aSmrg UNLOCK_APP(app); 581444c061aSmrg#endif /* GLOBALERRORS */ 582444c061aSmrg return old; 583444c061aSmrg} 584444c061aSmrg 585444c061aSmrgvoid XtSetWarningHandler(XtErrorHandler handler) 586444c061aSmrg{ 587444c061aSmrg#if GLOBALERRORS 588444c061aSmrg LOCK_PROCESS; 589444c061aSmrg if (handler != NULL) warningHandler = handler; 590444c061aSmrg else warningHandler = _XtDefaultWarning; 591444c061aSmrg UNLOCK_PROCESS; 592444c061aSmrg#else 593444c061aSmrg XtAppSetWarningHandler(_XtDefaultAppContext(),handler); 594444c061aSmrg#endif /* GLOBALERRORS */ 595444c061aSmrg} 596444c061aSmrg 597444c061aSmrgXtErrorHandler XtAppSetWarningHandler( 598444c061aSmrg XtAppContext app, 599444c061aSmrg XtErrorHandler handler) 600444c061aSmrg{ 601444c061aSmrg XtErrorHandler old; 602444c061aSmrg#if GLOBALERRORS 603444c061aSmrg LOCK_PROCESS; 604444c061aSmrg old = warningHandler; 605444c061aSmrg if (handler != NULL) warningHandler = handler; 606444c061aSmrg else warningHandler = _XtDefaultWarning; 607444c061aSmrg UNLOCK_PROCESS; 608444c061aSmrg#else 609444c061aSmrg LOCK_APP(app); 610444c061aSmrg old = app->warningHandler; 611444c061aSmrg if (handler != NULL) app->warningHandler = handler; 612444c061aSmrg else app->warningHandler = _XtDefaultWarning; 613444c061aSmrg UNLOCK_APP(app); 614444c061aSmrg#endif /* GLOBALERRORS */ 615444c061aSmrg return old; 616444c061aSmrg} 617444c061aSmrg 618444c061aSmrgvoid _XtSetDefaultErrorHandlers( 619444c061aSmrg XtErrorMsgHandler *errMsg, 620444c061aSmrg XtErrorMsgHandler *warnMsg, 621444c061aSmrg XtErrorHandler *err, 622444c061aSmrg XtErrorHandler *warn) 623444c061aSmrg{ 624444c061aSmrg#ifndef GLOBALERRORS 625444c061aSmrg LOCK_PROCESS; 626444c061aSmrg *errMsg = _XtDefaultErrorMsg; 627444c061aSmrg *warnMsg = _XtDefaultWarningMsg; 628444c061aSmrg *err = _XtDefaultError; 629444c061aSmrg *warn = _XtDefaultWarning; 630444c061aSmrg UNLOCK_PROCESS; 631444c061aSmrg#endif /* GLOBALERRORS */ 632444c061aSmrg} 633