Re: how to read a file into a GString
- From: Havoc Pennington <hp redhat com>
- To: Peter Jay Salzman <p dirac org>
- Cc: gtk-list gnome org
- Subject: Re: how to read a file into a GString
- Date: 28 Dec 2001 15:44:10 -0500
Peter Jay Salzman <p dirac org> writes:
> bleah. i was hoping for a more general function. something along the
> line of fgets.
It's really trivial using GString:
void
read_data (GString *str, FILE *f)
{
char buf[BUFSIZE];
if (fgets (buf, BUFSIZE, f) != NULL)
g_string_append (str, buf);
else if (ferror (f))
{
/* handle error */
}
else
{
/* end of file */
}
}
or something along those lines.
I thought g_file_get_contents() was implemented this way, but it isn't
anymore since it handles out-of-memory and thus doesn't use GString.
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]