strncpy.c 688 B

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