__assert.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright (C) 2002 Manuel Novoa III
  2. * An __assert() function compatible with the modified glibc assert.h
  3. * that is used by uClibc.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Library General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public
  16. * License along with this library; if not, write to the Free
  17. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. /* Oct 28, 2002
  20. *
  21. * ANSI/ISO C99 requires assert() to write to stderr. This means that
  22. * writing to STDERR_FILENO is insufficient, as the user could freopen
  23. * stderr. It is also insufficient to output to fileno(stderr) since
  24. * this would fail in the custom stream case. I didn't remove the
  25. * old code though, as it doesn't use stdio stream functionality
  26. * and is useful in debugging the stdio code.
  27. */
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. /* Get the prototype from assert.h as a double-check. */
  31. #undef NDEBUG
  32. #include <assert.h>
  33. #undef assert
  34. #define ASSERT_SHOW_PROGNAME 1
  35. static smallint in_assert; /* bss inits to 0. */
  36. void __assert(const char *assertion, const char * filename,
  37. unsigned int linenumber, register const char * function)
  38. {
  39. if (!in_assert) {
  40. in_assert = 1;
  41. fprintf(stderr,
  42. #ifdef ASSERT_SHOW_PROGNAME
  43. "%s: %s: %d: %s: Assertion `%s' failed.\n", __uclibc_progname,
  44. #else
  45. "%s: %d: %s: Assertion `%s' failed.\n",
  46. #endif
  47. filename,
  48. linenumber,
  49. /* Function name isn't available with some compilers. */
  50. ((function == NULL) ? "?function?" : function),
  51. assertion
  52. );
  53. }
  54. /* shouldn't we? fflush(stderr); */
  55. abort();
  56. }
  57. libc_hidden_def(__assert)