diff options
author | Barrucadu <mike@barrucadu.co.uk> | 2009-05-18 21:45:39 +0100 |
---|---|---|
committer | Barrucadu <mike@barrucadu.co.uk> | 2009-05-18 21:45:39 +0100 |
commit | 987d4c7ba787b30a965a4f01356672009b1ec2db (patch) | |
tree | 7e47320afdd3549621c38180a4396aa37bb02f3c | |
parent | 04d38d98141e80e8649d9099ea647c305a412f42 (diff) |
Added read_file_by_line() function
-rw-r--r-- | uzbl.c | 27 | ||||
-rw-r--r-- | uzbl.h | 3 |
2 files changed, 30 insertions, 0 deletions
@@ -152,6 +152,33 @@ str_replace (const char* search, const char* replace, const char* string) { return g_strjoinv (replace, g_strsplit (string, search, -1)); } +static gchar** +read_file_by_line (gchar *path) { + GIOChannel *chan = NULL; + gchar *readbuf = NULL; + gsize len; + gchar *lines[512]; + int i; + + chan = g_io_channel_new_file(path, "r", NULL); + + if (chan) { + while (g_io_channel_read_line(chan, &readbuf, &len, NULL, NULL) + == G_IO_STATUS_NORMAL) { + lines[i] = g_strdup (readbuf); + g_free (readbuf); + i ++; + } + + g_io_channel_unref (chan); + } else { + fprintf(stderr, "File '%s' not be read.\n", path); + } + + lines[i] = NULL; + return lines; +} + static gchar* parseenv (const char* string) { extern char** environ; @@ -204,6 +204,9 @@ itos(int val); static char * str_replace (const char* search, const char* replace, const char* string); +static gchar** +read_file_by_line (gchar *path); + static gchar* parseenv (const char* string); |