C标准库源代码

源代码在线查看: memmove.c

软件大小: 1707 K
上传用户: yl810406
关键词: 标准库 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				/***
				*memmove.c - contains memmove routine
				*
				*       Copyright (c) 1988-1997, Microsoft Corporation. All right reserved.
				*
				*Purpose:
				*       memmove() copies a source memory buffer to a destination buffer.
				*       Overlapping buffers are treated specially, to avoid propogation.
				*
				*******************************************************************************/
				
				#include 
				#include 
				
				#if defined (_M_ALPHA)
				#pragma function(memmove)
				#endif  /* defined (_M_ALPHA) */
				
				/***
				*memmove - Copy source buffer to destination buffer
				*
				*Purpose:
				*       memmove() copies a source memory buffer to a destination memory buffer.
				*       This routine recognize overlapping buffers to avoid propogation.
				*       For cases where propogation is not a problem, memcpy() can be used.
				*
				*Entry:
				*       void *dst = pointer to destination buffer
				*       const void *src = pointer to source buffer
				*       size_t count = number of bytes to copy
				*
				*Exit:
				*       Returns a pointer to the destination buffer
				*
				*Exceptions:
				*******************************************************************************/
				
				void * __cdecl memmove (
				        void * dst,
				        const void * src,
				        size_t count
				        )
				{
				        void * ret = dst;
				
				#if defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC)
				        {
				        extern void RtlMoveMemory( void *, const void *, size_t count );
				
				        RtlMoveMemory( dst, src, count );
				        }
				#else  /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */
				        if (dst = ((char *)src + count)) {
				                /*
				                 * Non-Overlapping Buffers
				                 * copy from lower addresses to higher addresses
				                 */
				                while (count--) {
				                        *(char *)dst = *(char *)src;
				                        dst = (char *)dst + 1;
				                        src = (char *)src + 1;
				                }
				        }
				        else {
				                /*
				                 * Overlapping Buffers
				                 * copy from higher addresses to lower addresses
				                 */
				                dst = (char *)dst + count - 1;
				                src = (char *)src + count - 1;
				
				                while (count--) {
				                        *(char *)dst = *(char *)src;
				                        dst = (char *)dst - 1;
				                        src = (char *)src - 1;
				                }
				        }
				#endif  /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */
				
				        return(ret);
				}
							

相关资源