Created
October 19, 2020 16:09
-
-
Save shawnfeng0/735f87fb5b9a702b896e9cf90af1fea6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void *memcpy(void *dst, void *src, unsigned n) { | |
if (!dst || !src) { | |
return nullptr; | |
} | |
auto dst_c = (char *) dst; | |
auto src_c = (char *) src; | |
if (dst_c < src || dst_c > (src_c + n)) { | |
while (n--) { | |
*dst_c++ = *src_c++; | |
} | |
} else { | |
while (n--) { | |
*(dst_c + n) = *(src_c + n); | |
} | |
} | |
return dst; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment