Re: how to read a file into a GString



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]