原创 自己刚写的一个内存拷贝函数~

2009-4-16 14:16 2638 8 8 分类: MCU/ 嵌入式

/*==================================


          函数:   CopyBuffer
          说明: 从源内存区向目标内存区顺序拷贝一定长度的内存块
          入口:  *SouPointer--源指针
                        *DesPointer--目标指针
                        Length-------拷贝长度
          出口:返回目的区的指针
 
===================================*/


CopyBuffer(void *SouPointer,void *DesPointer,uint16 Length)
{
     uint16 i;
     uint8 *D_Pointer;
     uint8 *S_Pointer;


     if ( (SouPointer==NULL)||(DesPointer==NULL) )
     {
          return;
     }


     if(DesPointer < SouPointer)
     {
          D_Pointer = (uint8 *)DesPointer;
          S_Pointer = (uint8 *)SouPointer;
          for (i = 0; i < Length; i++ )
          {
              *D_Pointer++ = *S_Pointer++ ;
          }
     }
     else
     {
          D_Pointer = ((uint8 *)DesPointer)+(Length - 1);
          S_Pointer = ((uint8 *)SouPointer)+(Length - 1);
          for(i = 0; i < Length; i )
          {
              *D_Pointer-- = *S_Pointer--;
          }
      }

      return DesPointer;
}

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
我要评论
0
8
关闭 站长推荐上一条 /3 下一条