errno.c 625 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <unistd.h>
  4. int* __errno_location(void)
  5. {
  6. static int __errno = 0;
  7. return &__errno;
  8. }
  9. static size_t _strlen(const char* str)
  10. {
  11. size_t len = 0;
  12. while (str[len] != '\0') {
  13. len++;
  14. }
  15. return len;
  16. }
  17. void
  18. __attribute__((noreturn))
  19. __attribute__((weak))
  20. __stack_chk_fail(void)
  21. {
  22. const char* msg = "***** stack overflow detected *****\n"
  23. "quiting...\n";
  24. write(STDERR_FILENO, msg, _strlen(msg));
  25. exit(-1);
  26. }
  27. void
  28. __attribute__((noreturn))
  29. __attribute__((weak))
  30. __stack_chk_fail_local(void)
  31. {
  32. __stack_chk_fail();
  33. }