test-stpcpy_chk.c 1.5 KB

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