__assert.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #define _STDIO_UTILITY /* For _stdio_fdout and _int10tostr. */
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <unistd.h>
  23. /* Get the prototype from assert.h as a double-check. */
  24. #undef NDEBUG
  25. #include <assert.h>
  26. #undef assert
  27. void __assert(const char *assertion, const char * filename,
  28. int linenumber, register const char * function)
  29. {
  30. char buf[__BUFLEN_INT10TOSTR];
  31. _stdio_fdout(STDERR_FILENO,
  32. #if 0
  33. program_name, /* TODO: support program_name like glibc? */
  34. ": ",
  35. #endif
  36. filename,
  37. ":",
  38. _int10tostr(buf+sizeof(buf)-1, linenumber),
  39. ": ",
  40. /* Function name isn't available with some compilers. */
  41. ((function == NULL) ? "?function?" : function),
  42. ": Assertion `",
  43. assertion,
  44. "' failed.\n",
  45. NULL
  46. );
  47. abort();
  48. }