Are there any simple standardized way of reading a full line from a socket that mallocs the memory for you? If so, what are they? If not, is there a way to do it in approximately O(1) time (obviously not including the time for the memory allocation).
Name:
Anonymous2008-08-20 14:22
Dynamic languages usually have a function to read an entire line into dynamically allocated memory. Tons of people use these functions every day, so why is it any different to want to do this in C? By the way, using fdopen is a total fucking hack and you know it.
An example of why I want a function like this: Say you're building a web server, and you want to read in the request headers. You could read them line by line, parsing each line as you go, or you could read the whole request at once until the client disconnects or something. Either way theres the possibility that the request is malformed and it could totally fuck up your application.
Obviously you could set the maximum amount of characters per line, because I believe there is an HTTP code specifically for that, but why?