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


Ignore:
Timestamp:
2023-10-27T19:38:31Z (20 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, topic/msim-upgrade, topic/simplify-dev-export
Children:
63ed840
Parents:
c89ae25 (diff), 694ca3d6 (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.
Message:

Merge code deduplication work

TL;DR: Added directory /common, which now contains the sole existing
copy of ADT, printf_core, and a few other pieces. Should make changes
to any of those less of a headache.

File:
1 edited

Legend:

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

    rc89ae25 r34120f10  
    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.