Back to index

glibc  2.9
memcpy.c
Go to the documentation of this file.
00001 /* Copy memory to memory until the specified number of bytes
00002    has been copied.  Overlap is NOT handled correctly.
00003    Copyright (C) 1991, 1997, 2003 Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005    Contributed by Torbjorn Granlund (tege@sics.se).
00006 
00007    The GNU C Library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2.1 of the License, or (at your option) any later version.
00011 
00012    The GNU C Library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Lesser General Public License for more details.
00016 
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with the GNU C Library; if not, write to the Free
00019    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00020    02111-1307 USA.  */
00021 
00022 #include <string.h>
00023 #include <memcopy.h>
00024 #include <pagecopy.h>
00025 
00026 #undef memcpy
00027 
00028 void *
00029 memcpy (dstpp, srcpp, len)
00030      void *dstpp;
00031      const void *srcpp;
00032      size_t len;
00033 {
00034   unsigned long int dstp = (long int) dstpp;
00035   unsigned long int srcp = (long int) srcpp;
00036 
00037   /* Copy from the beginning to the end.  */
00038 
00039   /* If there not too few bytes to copy, use word copy.  */
00040   if (len >= OP_T_THRES)
00041     {
00042       /* Copy just a few bytes to make DSTP aligned.  */
00043       len -= (-dstp) % OPSIZ;
00044       BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);
00045 
00046       /* Copy whole pages from SRCP to DSTP by virtual address manipulation,
00047         as much as possible.  */
00048 
00049       PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len);
00050 
00051       /* Copy from SRCP to DSTP taking advantage of the known alignment of
00052         DSTP.  Number of bytes remaining is put in the third argument,
00053         i.e. in LEN.  This number may vary from machine to machine.  */
00054 
00055       WORD_COPY_FWD (dstp, srcp, len, len);
00056 
00057       /* Fall out and copy the tail.  */
00058     }
00059 
00060   /* There are just a few bytes to copy.  Use byte memory operations.  */
00061   BYTE_COPY_FWD (dstp, srcp, len);
00062 
00063   return dstpp;
00064 }
00065 libc_hidden_builtin_def (memcpy)