wmemcpy() — Copy wide character

Standards

Standards / Extensions C or C++ Dependencies

ISO C Amendment
C99
Single UNIX Specification, Version 3

both  

Format

Non-XPG4:
#include <wchar.h>

wchar_t *wmemcpy(wchar_t * __restrict__s1, 
                 const wchar_t * __restrict__s2, size_t n);
XPG4:
#define _XOPEN_SOURCE
#define _MSE_PROTOS
#include <wchar.h>

wchar_t *wmemcpy(wchar_t *s1, const wchar_t *s2, size_t n);

General description

Copies n wide chars of the object pointed to by s2 to the object pointed to by s1.

Result of the copy is unpredictable if s1 and s2 overlap. If n has the value 0, wmemcpy copies zero wide characters.

Note: The function is now available as a built-in function under ARCH(7) when LP64 is not used.

Special behavior for XPG4: If you define any feature test macro specifying XPG4 behavior before the statement in your program source file to include the wchar header, then you must also define the _MSE_PROTOS feature test macro to make the declaration of the wmemcpy function in the wchar header available when you compile your program. Please see Table 1 for a list of XPG4 and other feature test macros.

Returned value

wmemcpy() returns the value of s1.

Example

#include <wchar.h>
#include <stdio.h>


main()
 {
  wchar_t  *in    = L"12345678";
  wchar_t  *out   = L"ABCDEFGH";
  wchar_t  *ptr;

  printf("-nExpected result: First 4 chars of in change");
  printf(" and are the same as first 4 chars of out");
  ptr = wmemcpy(in, out, 4);
  if (ptr == in)
       printf("-nArray in %ls array out %ls -n",in, out);
    else
      {
       printf("-n*** ERROR ***");
       printf(" returned pointer wrong");
      }
 }

Related information