diff options
author | Brendan Taylor <whateley@gmail.com> | 2010-11-02 21:14:48 -0600 |
---|---|---|
committer | Brendan Taylor <whateley@gmail.com> | 2010-11-02 21:56:12 -0600 |
commit | e0acf99635e715b088eee33f83e4524ed3c7f734 (patch) | |
tree | 8bc46735870bf7936a2dc6c102d68f9f898af07d /src/util.c | |
parent | 2f6fe6720ca69b58224bd5f45c9b47be9b7f8fbe (diff) |
moved for_each_line_in_file into util.c
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -89,3 +89,22 @@ str_replace (const char* search, const char* replace, const char* string) { return ret; } +gboolean +for_each_line_in_file(const gchar *path, void (*callback)(const gchar *l, void *c), void *user_data) { + gchar *line = NULL; + gsize len; + + GIOChannel *chan = g_io_channel_new_file(path, "r", NULL); + + if (chan) { + while (g_io_channel_read_line(chan, &line, &len, NULL, NULL) == G_IO_STATUS_NORMAL) { + callback(line, user_data); + g_free(line); + } + g_io_channel_unref (chan); + + return TRUE; + } + + return FALSE; +} |