@Karlos
Just being pedantic here, but:
a) If the stream end in immeditate EOF, your code trash memory *before* the buffer [0-1]. Not good.
b) The last char is not always a newline. If the stream ends (EOF) you now kill the last perfectly valid char. Not good.
Make it:
/* If the last char is a newline, kill it */
if (len && p->data[len-1] == '\n')
{
p->data[len-1] = '\0';
}
/* Note to anyone who thinks the char could be '\r' too: PC stdio libs have automagic "\r\n" -> "\n" at input and automagic "\n" -> "\r\n" at output. Or at least should have. :-) */