__assert.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Copyright (C) 1996 Robert de Bath <rdebath@cix.compulink.co.uk>
  2. * This file is part of the Linux-8086 C library and is distributed
  3. * under the GNU Library General Public License.
  4. */
  5. /*
  6. * Manuel Novoa III Dec 2000
  7. *
  8. * Converted to use my new (un)signed long (long) to string routines, which
  9. * are smaller than the previous functions and don't require static buffers.
  10. */
  11. #include <unistd.h>
  12. #include <string.h>
  13. #include <stdlib.h>
  14. #include <limits.h>
  15. #if (INT_MAX >> 31)
  16. /* We're set up for 32 bit ints */
  17. #error need to check size allocation for buffer 'buf'
  18. #endif
  19. extern char *__ltostr(char *buf, unsigned long uval, int base, int uppercase);
  20. static void errput(str)
  21. const char *str;
  22. {
  23. write(2, str, strlen(str));
  24. }
  25. void __assert(assertion, filename, linenumber, function)
  26. const char *assertion;
  27. const char *filename;
  28. int linenumber;
  29. const char *function;
  30. {
  31. char buf[12];
  32. errput(filename);
  33. errput(":");
  34. errput(__ltostr(buf + sizeof(buf) - 1, linenumber, 10, 0));
  35. errput(function ? ": " : "");
  36. errput(function ? function : "");
  37. errput(function ? "() " : "");
  38. errput(": Assertion \"");
  39. errput(assertion);
  40. errput("\" failed.\n");
  41. abort();
  42. }