/contrib/ntp/libisc/assertions.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 93 lines · 48 code · 13 blank · 32 comment · 3 complexity · 4ab49eb9b36f88a4a776a286a691dd91 MD5 · raw file

  1. /*
  2. * Copyright (C) 1997-2001 Internet Software Consortium.
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
  9. * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  10. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  11. * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  13. * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  14. * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  15. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. /* $Id: assertions.c,v 1.16 2001/07/16 03:52:05 mayer Exp $ */
  18. #include <config.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <isc/assertions.h>
  22. #include <isc/msgs.h>
  23. /*
  24. * Forward.
  25. */
  26. static void
  27. default_callback(const char *, int, isc_assertiontype_t, const char *);
  28. /*
  29. * Public.
  30. */
  31. LIBISC_EXTERNAL_DATA isc_assertioncallback_t isc_assertion_failed =
  32. default_callback;
  33. void
  34. isc_assertion_setcallback(isc_assertioncallback_t cb) {
  35. if (cb == NULL)
  36. isc_assertion_failed = default_callback;
  37. else
  38. isc_assertion_failed = cb;
  39. }
  40. const char *
  41. isc_assertion_typetotext(isc_assertiontype_t type) {
  42. const char *result;
  43. /*
  44. * These strings have purposefully not been internationalized
  45. * because they are considered to essentially be keywords of
  46. * the ISC development environment.
  47. */
  48. switch (type) {
  49. case isc_assertiontype_require:
  50. result = "REQUIRE";
  51. break;
  52. case isc_assertiontype_ensure:
  53. result = "ENSURE";
  54. break;
  55. case isc_assertiontype_insist:
  56. result = "INSIST";
  57. break;
  58. case isc_assertiontype_invariant:
  59. result = "INVARIANT";
  60. break;
  61. default:
  62. result = NULL;
  63. }
  64. return (result);
  65. }
  66. /*
  67. * Private.
  68. */
  69. static void
  70. default_callback(const char *file, int line, isc_assertiontype_t type,
  71. const char *cond)
  72. {
  73. fprintf(stderr, "%s:%d: %s(%s) %s.\n",
  74. file, line, isc_assertion_typetotext(type), cond,
  75. isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
  76. ISC_MSG_FAILED, "failed"));
  77. fflush(stderr);
  78. abort();
  79. /* NOTREACHED */
  80. }