xref: /onnv-gate/usr/src/lib/libc/port/i18n/wmemmove.c (revision 6812:febeba71273d)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*6812Sraf  * Common Development and Distribution License (the "License").
6*6812Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211219Sraf 
220Sstevel@tonic-gate /*
23*6812Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
29*6812Sraf #include "lint.h"
300Sstevel@tonic-gate #include <sys/types.h>
310Sstevel@tonic-gate #include <wchar.h>
320Sstevel@tonic-gate #include <limits.h>
330Sstevel@tonic-gate #include <string.h>
340Sstevel@tonic-gate #include "libc.h"
350Sstevel@tonic-gate 
360Sstevel@tonic-gate wchar_t *
wmemmove(wchar_t * ws1,const wchar_t * ws2,size_t n)370Sstevel@tonic-gate wmemmove(wchar_t *ws1, const wchar_t *ws2, size_t n)
380Sstevel@tonic-gate {
390Sstevel@tonic-gate 	wchar_t	*ows1;
400Sstevel@tonic-gate 	size_t	max = SIZE_MAX / sizeof (wchar_t);
410Sstevel@tonic-gate 
420Sstevel@tonic-gate 	if (n <= max) {
430Sstevel@tonic-gate 		return ((wchar_t *)memmove((void *)ws1,
44*6812Sraf 		    (const void *)ws2, n * sizeof (wchar_t)));
450Sstevel@tonic-gate 	}
460Sstevel@tonic-gate 
470Sstevel@tonic-gate 	ows1 = ws1;
480Sstevel@tonic-gate 	if (n != 0) {
490Sstevel@tonic-gate 		if (ws1 <= ws2) {
500Sstevel@tonic-gate 			do {
510Sstevel@tonic-gate 				*ws1++ = *ws2++;
520Sstevel@tonic-gate 			} while (--n != 0);
530Sstevel@tonic-gate 		} else {
540Sstevel@tonic-gate 			ws2 += n;
550Sstevel@tonic-gate 			ws1 += n;
560Sstevel@tonic-gate 			do {
570Sstevel@tonic-gate 				*--ws1 = *--ws2;
580Sstevel@tonic-gate 			} while (--n != 0);
590Sstevel@tonic-gate 		}
600Sstevel@tonic-gate 	}
610Sstevel@tonic-gate 	return (ows1);
620Sstevel@tonic-gate }
63