Changeset dc5c303 in mainline for kernel/generic/src/lib/mem.c


Ignore:
Timestamp:
2023-12-28T13:59:23Z (2 years ago)
Author:
GitHub <noreply@…>
Children:
6b66de6b
Parents:
42c2e65 (diff), f87ff8e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
boba-buba <120932204+boba-buba@…> (2023-12-28 13:59:23)
git-committer:
GitHub <noreply@…> (2023-12-28 13:59:23)
Message:

Merge branch 'master' into topic/packet-capture

File:
1 edited

Legend:

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

    r42c2e65 rdc5c303  
    4141 */
    4242
    43 #include <mem.h>
     43#include <memw.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  */
    91 void *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 
    12479/** @}
    12580 */
Note: See TracChangeset for help on using the changeset viewer.