Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/lib/mem.c

    rb169619 r174156fd  
    4141 */
    4242
    43 #include <memw.h>
     43#include <mem.h>
    4444#include <typedefs.h>
    4545
     
    7777}
    7878
     79/** Move memory block with possible overlapping.
     80 *
     81 * Copy cnt bytes from src address to dst address. The source
     82 * and destination memory areas may overlap.
     83 *
     84 * @param dst Destination address to copy to.
     85 * @param src Source address to copy from.
     86 * @param cnt Number of bytes to copy.
     87 *
     88 * @return Destination address.
     89 *
     90 */
     91void *memmove(void *dst, const void *src, size_t cnt)
     92{
     93        /* Nothing to do? */
     94        if (src == dst)
     95                return dst;
     96
     97        /* Non-overlapping? */
     98        if ((dst >= src + cnt) || (src >= dst + cnt))
     99                return memcpy(dst, src, cnt);
     100
     101        uint8_t *dp;
     102        const uint8_t *sp;
     103
     104        /* Which direction? */
     105        if (src > dst) {
     106                /* Forwards. */
     107                dp = dst;
     108                sp = src;
     109
     110                while (cnt-- != 0)
     111                        *dp++ = *sp++;
     112        } else {
     113                /* Backwards. */
     114                dp = dst + (cnt - 1);
     115                sp = src + (cnt - 1);
     116
     117                while (cnt-- != 0)
     118                        *dp-- = *sp--;
     119        }
     120
     121        return dst;
     122}
     123
    79124/** @}
    80125 */
Note: See TracChangeset for help on using the changeset viewer.