On 07/19/2011 04:30 PM, Paul Berry wrote: > On 19 July 2011 13:15, Ian Romanick <[email protected]> wrote:
On the issue of std::stringbuf, I'm siding with Paul here. This
concise, safe function definition:
static string read_stdin_to_eof()
{
stringbuf sb;
cin.get(sb, '\0');
return sb.str();
}
is vastly more palatable than this bug-prone mess:
> static char *read_stdin_to_eof()
> {
> char buffer[4096] = "\0";
> size_t len = 0;
> char *result = (char *) malloc(1);
> while(fgets(buffer, sizeof(buffer), stdin))
> {
> size_t bytes_read = strlen(buffer);
> result = (char *) realloc(result, len + bytes_read + 1);
> memcpy(result + len, buffer, bytes_read);
> len += bytes_read;
> }
> result[len] = '\0';
> return result;
> }
--
Chad Versace
[email protected]
signature.asc
Description: OpenPGP digital signature
_______________________________________________ mesa-dev mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/mesa-dev
