OSDN Git Service

3c545ac3206604d6d6dab8f45e0d66aab292c2f8
[pf3gnuchains/pf3gnuchains3x.git] / winsup / mingw / mingwex / wmemmove.c
1 /*      This source code was extracted from the Q8 package created and placed
2     in the PUBLIC DOMAIN by Doug Gwyn <gwyn@arl.mil>
3     last edit:  1999/11/05      gwyn@arl.mil
4
5     Implements subclause 7.24 of ISO/IEC 9899:1999 (E).
6
7         It supports an encoding where all char codes are mapped
8         to the *same* code values within a wchar_t or wint_t,
9         so long as no other wchar_t codes are used by the program.
10
11 */
12
13 #include        <errno.h>
14 #include        <stdio.h>
15 #include        <stdlib.h>
16 #include        <wchar.h>
17
18 wchar_t *
19 wmemmove(s1, s2, n)
20         register wchar_t                *s1;
21         register const wchar_t  *s2;
22         register size_t                 n;
23         {
24         wchar_t                         *orig_s1 = s1;
25
26         if ( s1 == NULL || s2 == NULL || n == 0 )
27                 return orig_s1;         /* robust */
28
29         /* XXX -- The following test works only within a flat address space! */
30         if ( s2 >= s1 )
31                 for ( ; n > 0; --n )
32                         *s1++ = *s2++;
33         else    {
34                 s1 += n;
35                 s2 += n;
36
37                 for ( ; n > 0; --n )
38                         *--s1 = *--s2;
39                 }
40
41         return orig_s1;
42         }
43