memmove.c revision 82333da930cddbdbdfe38acf480e9c35fb875d2d
4015N/A/*
4015N/A * CDDL HEADER START
4015N/A *
4015N/A * The contents of this file are subject to the terms of the
4015N/A * Common Development and Distribution License (the "License").
4015N/A * You may not use this file except in compliance with the License.
4015N/A *
4015N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4015N/A * or http://www.opensolaris.org/os/licensing.
4015N/A * See the License for the specific language governing permissions
4015N/A * and limitations under the License.
4015N/A *
4015N/A * When distributing Covered Code, include this CDDL HEADER in each
4015N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4015N/A * If applicable, add the following below this CDDL HEADER, with the
4015N/A * fields enclosed by brackets "[]" replaced with your own identifying
4015N/A * information: Portions Copyright [yyyy] [name of copyright owner]
4015N/A *
4015N/A * CDDL HEADER END
4015N/A */
4015N/A
4015N/A/*
4015N/A * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
4015N/A */
4015N/A
4015N/A/* Copyright (c) 1988 AT&T */
4015N/A/* All Rights Reserved */
4015N/A
4015N/A#if !defined(_KMDB) && !defined(_KERNEL)
4015N/A
4015N/A#include "lint.h"
4015N/A
4015N/A#endif /* !_KMDB && !_KERNEL */
4015N/A
4015N/A/*
4015N/A * The SunStudio compiler may generate calls to _memmove; So we
4015N/A * need to make sure that the correct symbol exists for these calls.
4015N/A */
4015N/A#pragma weak _memmove = memmove
4015N/A
4015N/A#include <sys/types.h>
4015N/A
4015N/A#if defined(_KERNEL)
4015N/A#include <sys/systm.h>
4015N/A#else
4015N/A#include <string.h>
4015N/A#include <memory.h>
4015N/A#endif
4015N/A
4015N/A/*
4015N/A * Copy s0 to s, always copy n bytes.
4015N/A * Return s
4015N/A * Copying between objects that overlap will take place correctly
4015N/A */
4015N/Avoid *
4015N/Amemmove(void *s, const void *s0, size_t n)
4015N/A{
4015N/A if (n != 0) {
4015N/A char *s1 = s;
4015N/A const char *s2 = s0;
4015N/A
4015N/A if (s1 <= s2) {
4015N/A do {
4015N/A *s1++ = *s2++;
4015N/A } while (--n != 0);
4015N/A } else {
4015N/A s2 += n;
4015N/A s1 += n;
4015N/A do {
4015N/A *--s1 = *--s2;
4015N/A } while (--n != 0);
}
}
return (s);
}