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-2013 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 program is free software: you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by the
  8. Free Software Foundation; either version 3 of the License, or any
  9. later version.
  10. This program 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 General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  16. #include <config.h>
  17. #include <string.h>
  18. #include <stdlib.h>
  19. #undef __stpcpy
  20. #if defined(_LIBC) || (defined(__MACH__) && defined(stpcpy))
  21. # undef stpcpy
  22. #endif
  23. #ifndef weak_alias
  24. # define __stpcpy stpcpy
  25. #endif
  26. /* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */
  27. char *
  28. __stpcpy (char *dest, const char *src)
  29. {
  30. char *d = dest;
  31. const char *s = src;
  32. do
  33. *d++ = *s;
  34. while (*s++ != '\0');
  35. return d - 1;
  36. }
  37. #ifdef weak_alias
  38. weak_alias (__stpcpy, stpcpy)
  39. #endif