stpncpy.c 811 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (C) 2002 Manuel Novoa III
  3. * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
  4. *
  5. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. */
  7. #include "_string.h"
  8. #ifdef WANT_WIDE
  9. # define __Wstpncpy __wcpncpy
  10. # define Wstpncpy wcpncpy
  11. #else
  12. # define __Wstpncpy __stpncpy
  13. # define Wstpncpy stpncpy
  14. #endif
  15. Wchar attribute_hidden *__Wstpncpy(register Wchar * __restrict s1,
  16. register const Wchar * __restrict s2,
  17. size_t n)
  18. {
  19. Wchar *s = s1;
  20. const Wchar *p = s2;
  21. #ifdef __BCC__
  22. while (n--) {
  23. if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
  24. ++s;
  25. }
  26. return s1 + (s2 - p);
  27. #else
  28. while (n) {
  29. if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
  30. ++s;
  31. --n;
  32. }
  33. return s1 + (s2 - p);
  34. #endif
  35. }
  36. strong_alias(__Wstpncpy,Wstpncpy)