strncpy.c 716 B

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