Consider the following C function which takes as argument a string, which is then stored inside a struct:
struct mystruct* usestring(char* string)
{
struct mystruct *struct;
struct = malloc(sizeof(struct mystruct));
struct->string = string;
return struct;
}
My understanding is that the string passed to the function is the same string that is stored inside the struct.
What is the proper etiquette in this situation? Should I make a copy of the string and store that in the struct, or should I expect that the function caller will not modify the string later?