test-stpcpy_chk.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Test and measure stpcpy checking functions.
  2. Copyright (C) 1999-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Written by Jakub Jelinek <jakub@redhat.com>, 1999.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #define STRCPY_RESULT(dst, len) ((dst) + (len))
  17. #define TEST_MAIN
  18. #define TEST_NAME "stpcpy_chk"
  19. #include "../string/test-string.h"
  20. extern void __attribute__ ((noreturn)) __chk_fail (void);
  21. char *simple_stpcpy_chk (char *, const char *, size_t);
  22. extern char *normal_stpcpy (char *, const char *, size_t)
  23. __asm ("stpcpy");
  24. extern char *__stpcpy_chk (char *, const char *, size_t);
  25. IMPL (simple_stpcpy_chk, 0)
  26. IMPL (normal_stpcpy, 1)
  27. IMPL (__stpcpy_chk, 2)
  28. char *
  29. simple_stpcpy_chk (char *dst, const char *src, size_t len)
  30. {
  31. if (! len)
  32. __chk_fail ();
  33. while ((*dst++ = *src++) != '\0')
  34. if (--len == 0)
  35. __chk_fail ();
  36. return dst - 1;
  37. }
  38. #include "test-strcpy_chk.c"