gsl_err__error.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* err/error.c
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. #include "gsl__config.h"
  20. #include <stddef.h>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include "gsl_errno.h"
  24. #include "gsl_message.h"
  25. gsl_error_handler_t * gsl_error_handler = NULL;
  26. static void no_error_handler (const char *reason, const char *file, int line, int gsl_errno);
  27. void
  28. gsl_error (const char * reason, const char * file, int line, int gsl_errno)
  29. {
  30. if (gsl_error_handler)
  31. {
  32. (*gsl_error_handler) (reason, file, line, gsl_errno);
  33. return ;
  34. }
  35. gsl_stream_printf ("ERROR", file, line, reason);
  36. fflush (stdout);
  37. fprintf (stderr, "Default GSL error handler invoked.\n");
  38. fflush (stderr);
  39. abort ();
  40. }
  41. gsl_error_handler_t *
  42. gsl_set_error_handler (gsl_error_handler_t * new_handler)
  43. {
  44. gsl_error_handler_t * previous_handler = gsl_error_handler;
  45. gsl_error_handler = new_handler;
  46. return previous_handler;
  47. }
  48. gsl_error_handler_t *
  49. gsl_set_error_handler_off (void)
  50. {
  51. gsl_error_handler_t * previous_handler = gsl_error_handler;
  52. gsl_error_handler = no_error_handler;
  53. return previous_handler;
  54. }
  55. static void
  56. no_error_handler (const char *reason, const char *file, int line, int gsl_errno)
  57. {
  58. /* do nothing */
  59. reason = 0;
  60. file = 0;
  61. line = 0;
  62. gsl_errno = 0;
  63. return;
  64. }