Re: how to read a file into a GString
- From: Owen Taylor <otaylor redhat com>
- To: Peter Jay Salzman <p dirac org>
- Cc: Havoc Pennington <hp redhat com>, gtk-list gnome org
- Subject: Re: how to read a file into a GString
- Date: 29 Dec 2001 14:29:12 -0500
Peter Jay Salzman <p dirac org> writes:
> bleah. i was hoping for a more general function. something along the
> line of fgets.
>
> unfortunately, reading the entire file at once would make my code bigger
> and uglier, rather than smaller and cleaner.
>
> since i'm reading /usr/share/dict/words, it would also be a PITA for the
> user. many small accesses would, in the long run, be more expensive to
> do, but **much** less expensive to the user's patience.
You can look at the GIOChannel functions in GLib-1.3 if you are
to use GLib-1.3:
GIOStatus g_io_channel_read_line (GIOChannel *channel,
gchar **str_return,
gsize *length,
gsize *terminator_pos,
GError **error);
GIOStatus g_io_channel_read_line_string (GIOChannel *channel,
GString *buffer,
gsize *terminator_pos,
GError **error);
Or, more simply, you can cut-and-paste the code for:
gint pango_read_line (FILE *stream,
GString *str);
[ It's "publically exported" from Pango, because I wanted it in
GTK+, but I wouldn't really advise using it since it has no
logical reason to be in Pango ]
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]