zixie1991 / cplusplus-exercise

C++编程练习。。。
8 stars 1 forks source link

字符串 #15

Open zixie1991 opened 7 years ago

zixie1991 commented 7 years ago

字符串

memcopy 和 memmove

#ifndef __HAVE_ARCH_MEMCPY  
/**  
 * memcpy - Copy one area of memory to another  
 * @dest: Where to copy to  
 * @src: Where to copy from  
 * @count: The size of the area.  
 *  
 * You should not use this function to access IO space, use memcpy_toio()  
 * or memcpy_fromio() instead.  
 */  
void *memcpy(void *dest, const void *src, size_t count)  
{  
        char *tmp = dest;  
        const char *s = src;  

        while (count--)  
                *tmp++ = *s++;  
        return dest;  
}  
EXPORT_SYMBOL(memcpy);  
#endif  

#ifndef __HAVE_ARCH_MEMMOVE  
/**  
 * memmove - Copy one area of memory to another  
 * @dest: Where to copy to  
 * @src: Where to copy from  
 * @count: The size of the area.  
 *  
 * Unlike memcpy(), memmove() copes with overlapping areas.  
 */  
void *memmove(void *dest, const void *src, size_t count)  
{  
        char *tmp;  
        const char *s;  

        if (dest <= src) {  
                tmp = dest;  
                s = src;  
                while (count--)  
                        *tmp++ = *s++;  
        } else {  
                tmp = dest;  
                tmp += count;  
                s = src;  
                s += count;  
                while (count--)  
                        *--tmp = *--s;  
        }  
        return dest;  
}  
EXPORT_SYMBOL(memmove);  
#endif