stpncpy.c 775 B

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