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