memcpy.c
上传用户:shenzhenrh
上传日期:2013-05-12
资源大小:2904k
文件大小:2k
源码类别:

信息检索与抽取

开发平台:

Unix_Linux

  1. /* memcpy -- copy memory to memory until the specified number of bytes
  2.    has been copied.  Overlap is NOT handled correctly.
  3.    Copyright (C) 1991 Free Software Foundation, Inc.
  4.    Contributed by Torbjorn Granlund (tege@sics.se).
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with the GNU C Library; see the file COPYING.LIB.  If
  15. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16. Cambridge, MA 02139, USA.  */
  17. /*
  18.   Removed the word-boundary optimizations.  Include <misc.h> and "mem.h"
  19.   for declarations.
  20.   
  21.   mgd@santafe.edu 1998-07-08. */
  22. #include <misc.h>
  23. #include "mem.h"
  24. /* Copy exactly NBYTES bytes from SRC_BP to DST_BP,
  25.    without any assumptions about alignment of the pointers.  */
  26. #define BYTE_COPY_FWD(dst_bp, src_bp, nbytes)                                 
  27.   do                                                                          
  28.     {                                                                         
  29.       size_t __nbytes = (nbytes);                                             
  30.       while (__nbytes > 0)                                                    
  31.         {                                                                     
  32.           byte __x = ((byte *) src_bp)[0];                                    
  33.           src_bp += 1;                                                        
  34.           __nbytes -= 1;                                                      
  35.           ((byte *) dst_bp)[0] = __x;                                         
  36.           dst_bp += 1;                                                        
  37.         }                                                                     
  38.     } while (0) 
  39. void *
  40. memcpy (void *dstpp, const void *srcpp, size_t len)
  41. {
  42.   unsigned long int dstp = (long int) dstpp;
  43.   unsigned long int srcp = (long int) srcpp;
  44.   BYTE_COPY_FWD (dstp, srcp, len);
  45.   return dstpp;
  46. }