aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Barrucadu <mike@barrucadu.co.uk>2009-05-18 21:45:39 +0100
committerGravatar Barrucadu <mike@barrucadu.co.uk>2009-05-18 21:45:39 +0100
commit987d4c7ba787b30a965a4f01356672009b1ec2db (patch)
tree7e47320afdd3549621c38180a4396aa37bb02f3c
parent04d38d98141e80e8649d9099ea647c305a412f42 (diff)
Added read_file_by_line() function
-rw-r--r--uzbl.c27
-rw-r--r--uzbl.h3
2 files changed, 30 insertions, 0 deletions
diff --git a/uzbl.c b/uzbl.c
index 113f5fe..82258cf 100644
--- a/uzbl.c
+++ b/uzbl.c
@@ -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;
diff --git a/uzbl.h b/uzbl.h
index 0d8be65..7ff6584 100644
--- a/uzbl.h
+++ b/uzbl.h
@@ -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);