Skip to content

Instantly share code, notes, and snippets.

@shawnfeng0
Created October 19, 2020 16:09
Show Gist options
  • Save shawnfeng0/735f87fb5b9a702b896e9cf90af1fea6 to your computer and use it in GitHub Desktop.
Save shawnfeng0/735f87fb5b9a702b896e9cf90af1fea6 to your computer and use it in GitHub Desktop.
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