How does realloc know how much to copy?
how does realloc know the size of original data?

     void *realloc(void *ptr, size_t size);

So, if the implementation is like this:

     temp = malloc(size);
     memcpy(.. // How much to copy?
     free(ptr);
     return temp;

I realize this is not the original implementation, and realloc doesn't always do free, but when it does, how much does it copy?
How does realloc know how much to copy?
===

how does realloc know the size of original data?

     void *realloc(void *ptr, size_t size);

So, if the implementation is like this:

     temp = malloc(size);
     memcpy(.. // How much to copy?
     free(ptr);
     return temp;

I realize this is not the original implementation, and realloc doesn't always do free, but when it does, how much does it copy?