Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2. FUNCTION
  3.         <<wcsncpy>>---copy part of a wide-character string
  4.  
  5. ANSI_SYNOPSIS
  6.         #include <wchar.h>
  7.         wchar_t *wcsncpy(wchar_t *__restrict <[s1]>,
  8.                         const wchar_t *__restrict <[s2]>, size_t <[n]>);
  9.  
  10. TRAD_SYNOPSIS
  11.         wchar_t *wcsncpy(<[s1]>, <[s2]>, <[n]>
  12.         wchar_t *__restrict <[s1]>;
  13.         const wchar_t *__restrict <[s2]>;
  14.         size_t <[n]>;
  15.  
  16. DESCRIPTION
  17.         The <<wcsncpy>> function copies not more than <[n]> wide-character codes
  18.         (wide-character codes that follow a null wide-character code are not
  19.         copied) from the array pointed to by <[s2]> to the array pointed to
  20.         by <[s1]>. If copying takes place between objects that overlap, the
  21.         behaviour is undefined.  Note that if <[s1]> contains more than <[n]>
  22.         wide characters before its terminating null, the result is not
  23.         null-terminated.
  24.  
  25.         If the array pointed to by <[s2]> is a wide-character string that is
  26.         shorter than <[n]> wide-character codes, null wide-character codes are
  27.         appended to the copy in the array pointed to by <[s1]>, until <[n]>
  28.         wide-character codes in all are written.
  29.  
  30. RETURNS
  31.         The <<wcsncpy>> function returns <[s1]>; no return value is reserved to
  32.         indicate an error.
  33.  
  34. PORTABILITY
  35. ISO/IEC 9899; POSIX.1.
  36.  
  37. No supporting OS subroutines are required.
  38. */
  39.  
  40. #include <_ansi.h>
  41. #include <wchar.h>
  42.  
  43. wchar_t *
  44. _DEFUN (wcsncpy, (s1, s2, n),
  45.         wchar_t *__restrict s1 _AND
  46.         _CONST wchar_t *__restrict s2 _AND
  47.         size_t n)
  48. {
  49.   wchar_t *dscan=s1;
  50.  
  51.   while(n > 0)
  52.     {
  53.       --n;
  54.       if((*dscan++ = *s2++) == L'\0')  break;
  55.     }
  56.   while(n-- > 0)  *dscan++ = L'\0';
  57.  
  58.   return s1;
  59. }
  60.