errors.c (820B)
1 /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail> 2 * See LICENSE file for license details. 3 */ 4 #include "x11.h" 5 6 extern ErrorCode ignored_xerrors[]; 7 static bool _trap_errors; 8 static long nerrors; 9 10 int 11 errorhandler(Display *dpy, XErrorEvent *error) { 12 ErrorCode *e; 13 14 USED(dpy); 15 16 if(_trap_errors) { 17 nerrors++; 18 return 0; 19 } 20 21 e = ignored_xerrors; 22 if(e) 23 for(; e->rcode || e->ecode; e++) 24 if((e->rcode == 0 || e->rcode == error->request_code) 25 && (e->ecode == 0 || e->ecode == error->error_code)) 26 return 0; 27 28 fprint(2, "%s: fatal error: Xrequest code=%d, Xerror code=%d\n", 29 argv0, error->request_code, error->error_code); 30 return xlib_errorhandler(display, error); /* calls exit() */ 31 } 32 33 int 34 traperrors(bool enable) { 35 36 sync(); 37 _trap_errors = enable; 38 if (enable) 39 nerrors = 0; 40 return nerrors; 41 }