stpncpy.c 748 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. #else
  11. # define Wstpncpy stpncpy
  12. #endif
  13. Wchar *Wstpncpy(register Wchar * __restrict s1,
  14. register const Wchar * __restrict s2,
  15. size_t n)
  16. {
  17. Wchar *s = s1;
  18. const Wchar *p = s2;
  19. #ifdef __BCC__
  20. while (n--) {
  21. if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
  22. ++s;
  23. }
  24. return s1 + (s2 - p);
  25. #else
  26. while (n) {
  27. if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
  28. ++s;
  29. --n;
  30. }
  31. return s1 + (s2 - p);
  32. #endif
  33. }
  34. #ifndef WANT_WIDE
  35. libc_hidden_def(stpncpy)
  36. #endif