stpcpy.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* stpcpy.c -- copy a string and return pointer to end of new string
  2. Copyright (C) 1992, 1995, 1997-1998, 2006, 2009-2023 Free Software
  3. Foundation, Inc.
  4. NOTE: The canonical source of this file is maintained with the GNU C Library.
  5. Bugs can be reported to bug-glibc@prep.ai.mit.edu.
  6. This file is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU Lesser General Public License as
  8. published by the Free Software Foundation; either version 2.1 of the
  9. License, or (at your option) any later version.
  10. This file 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
  13. GNU Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public License
  15. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  16. #include <config.h>
  17. #include <string.h>
  18. #undef __stpcpy
  19. #ifdef _LIBC
  20. # undef stpcpy
  21. #endif
  22. #ifndef weak_alias
  23. # define __stpcpy stpcpy
  24. #endif
  25. /* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */
  26. char *
  27. __stpcpy (char *dest, const char *src)
  28. {
  29. register char *d = dest;
  30. register const char *s = src;
  31. do
  32. *d++ = *s;
  33. while (*s++ != '\0');
  34. return d - 1;
  35. }
  36. #ifdef weak_alias
  37. weak_alias (__stpcpy, stpcpy)
  38. #endif