Changeset b169619 in mainline for kernel/generic/src/lib/mem.c
- Timestamp:
- 2023-10-27T17:38:32Z (15 months ago)
- Branches:
- master, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 44e8541
- Parents:
- c89ae25
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2023-10-27 13:19:20)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2023-10-27 17:38:32)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/lib/mem.c
rc89ae25 rb169619 41 41 */ 42 42 43 #include <mem .h>43 #include <memw.h> 44 44 #include <typedefs.h> 45 45 … … 77 77 } 78 78 79 /** Move memory block with possible overlapping.80 *81 * Copy cnt bytes from src address to dst address. The source82 * 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 124 79 /** @} 125 80 */
Note:
See TracChangeset
for help on using the changeset viewer.