error.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* Copyright (C) 2005-2022 Free Software Foundation, Inc.
  2. Contributed by Richard Henderson <rth@redhat.com>.
  3. This file is part of the GNU Offloading and Multi Processing Library
  4. (libgomp).
  5. Libgomp is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3, or (at your option)
  8. any later version.
  9. Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. more details.
  13. Under Section 7 of GPL version 3, you are granted additional
  14. permissions described in the GCC Runtime Library Exception, version
  15. 3.1, as published by the Free Software Foundation.
  16. You should have received a copy of the GNU General Public License and
  17. a copy of the GCC Runtime Library Exception along with this program;
  18. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. <http://www.gnu.org/licenses/>. */
  20. /* This file contains routines used to signal errors. Most places in the
  21. OpenMP API do not make any provision for failure, so we can't just
  22. defer the decision on reporting the problem to the user; we must do it
  23. ourselves or not at all. */
  24. /* ??? Is this about what other implementations do? Assume stderr hasn't
  25. been pointed somewhere unsafe? */
  26. #include "libgomp.h"
  27. #include <stdarg.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #undef gomp_vdebug
  31. void
  32. gomp_vdebug (int kind __attribute__ ((unused)), const char *msg, va_list list)
  33. {
  34. if (gomp_debug_var)
  35. vfprintf (stderr, msg, list);
  36. }
  37. #undef gomp_debug
  38. void
  39. gomp_debug (int kind, const char *msg, ...)
  40. {
  41. va_list list;
  42. va_start (list, msg);
  43. gomp_vdebug (kind, msg, list);
  44. va_end (list);
  45. }
  46. void
  47. gomp_verror (const char *fmt, va_list list)
  48. {
  49. fputs ("\nlibgomp: ", stderr);
  50. vfprintf (stderr, fmt, list);
  51. fputc ('\n', stderr);
  52. }
  53. void
  54. gomp_error (const char *fmt, ...)
  55. {
  56. va_list list;
  57. va_start (list, fmt);
  58. gomp_verror (fmt, list);
  59. va_end (list);
  60. }
  61. void
  62. gomp_vfatal (const char *fmt, va_list list)
  63. {
  64. gomp_verror (fmt, list);
  65. exit (EXIT_FAILURE);
  66. }
  67. void
  68. gomp_fatal (const char *fmt, ...)
  69. {
  70. va_list list;
  71. va_start (list, fmt);
  72. gomp_vfatal (fmt, list);
  73. va_end (list);
  74. }
  75. void
  76. GOMP_warning (const char *msg, size_t msglen)
  77. {
  78. if (msg && msglen == (size_t) -1)
  79. gomp_error ("error directive encountered: %s", msg);
  80. else if (msg)
  81. {
  82. fputs ("\nlibgomp: error directive encountered: ", stderr);
  83. fwrite (msg, 1, msglen, stderr);
  84. fputc ('\n', stderr);
  85. }
  86. else
  87. gomp_error ("error directive encountered");
  88. }
  89. void
  90. GOMP_error (const char *msg, size_t msglen)
  91. {
  92. if (msg && msglen == (size_t) -1)
  93. gomp_fatal ("fatal error: error directive encountered: %s", msg);
  94. else if (msg)
  95. {
  96. fputs ("\nlibgomp: fatal error: error directive encountered: ", stderr);
  97. fwrite (msg, 1, msglen, stderr);
  98. fputc ('\n', stderr);
  99. exit (EXIT_FAILURE);
  100. }
  101. else
  102. gomp_fatal ("fatal error: error directive encountered");
  103. }