Life is Good.

Enhance Tech and English
随笔 - 65, 文章 - 20, 评论 - 21, 引用 - 0
数据加载中……

11 - memcpy

/***
*memcpy - Copy source buffer to destination buffer
*
*Purpose:
*       memcpy() copies a source memory buffer to a destination memory buffer.
*       This routine does NOT recognize overlapping buffers, and thus can lead
*       to propogation.
*
*       For cases where propogation must be avoided, memmove() must 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 memcpy (
  
void * dst,
  
const void * src,
  size_t count
  )
{
  
void * ret = dst;
  
/*
  * copy from lower addresses to higher addresses
  
*/
  
while (count--) {
    
*(char *)dst = *(char *)src;
    dst 
= (char *)dst + 1;
    src 
= (char *)src + 1;
  }

  
return(ret);
}

posted on 2011-06-11 21:30 Mike Song 阅读(243) 评论(0)  编辑 收藏 引用 所属分类: C字符串函数源码分析


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理