Is there any way to do this? Properly speaking, I need a portable way, but non-portable one would be useful too. Thanks.
Clarification: I got a buffer that contains zero terminated string (or many strings, as it may be when using strtok) and I need to copy string pointed by an arbitrary pointer (new_string) to that buffer. As far as I don't know actual buffer size (let us say, it's impossible), I need to realloc it (except in the case of strlen(buffer) >= strlen(new_string) - here buffer definitely has enough room to store new_string) and then copy new_string to reallocated buffer. And here's the problem: if new_string points to string somewhere inside buffer, it may become invalid after realloc. So I need to detect this special case and handle it appropriately.