aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-util.c-8611
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@helixcode.com>2000-05-07 01:04:10 +0800
committerChris Lahey <clahey@src.gnome.org>2000-05-07 01:04:10 +0800
commit7453ffb6a86769bd22ce01da43fbbe919bef861d (patch)
tree7ae0da105d87b7bff10780700d9f9f83aa2a6959 /e-util/e-util.c-8611
parent9b57702d4d406955ce3ec2e841253ed3efe3bbb8 (diff)
downloadgsoc2013-evolution-7453ffb6a86769bd22ce01da43fbbe919bef861d.tar.gz
gsoc2013-evolution-7453ffb6a86769bd22ce01da43fbbe919bef861d.tar.zst
gsoc2013-evolution-7453ffb6a86769bd22ce01da43fbbe919bef861d.zip
Got rid of some warnings.
2000-05-06 Christopher James Lahey <clahey@helixcode.com> * e-html-utils.c: Got rid of some warnings. * e-util.c, e-util.h: Added e_read_file which takes a filename and returns a newly allocated string containing the contents of that file. svn path=/trunk/; revision=2828
Diffstat (limited to 'e-util/e-util.c-8611')
-rw-r--r--e-util/e-util.c-861152
1 files changed, 52 insertions, 0 deletions
diff --git a/e-util/e-util.c-8611 b/e-util/e-util.c-8611
index f2d787f37e..d5603d3dfa 100644
--- a/e-util/e-util.c-8611
+++ b/e-util/e-util.c-8611
@@ -22,6 +22,9 @@
#include <glib.h>
#include <gtk/gtkobject.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
#include "e-util.h"
@@ -52,3 +55,52 @@ e_free_object_list (GList *list)
g_list_free (list);
}
+
+#define BUFF_SIZE 1024
+
+char *
+e_read_file(const char *filename)
+{
+ int fd;
+ char buffer[BUFF_SIZE];
+ GList *list = NULL, *list_iterator;
+ GList *lengths = NULL, *lengths_iterator;
+ int length = 0;
+ int bytes;
+ char *ret_val;
+
+ fd = open(filename, O_RDONLY);
+ if (fd == -1)
+ return NULL;
+ bytes = read(fd, buffer, BUFF_SIZE);
+ while (bytes) {
+ if (bytes > 0) {
+ list = g_list_prepend(list, g_strndup(buffer, bytes));
+ lengths = g_list_prepend(lengths, GINT_TO_POINTER(bytes));
+ length += bytes;
+ } else {
+ if (errno != EINTR) {
+ close(fd);
+ g_list_foreach(list, (GFunc) g_free, NULL);
+ g_list_free(list);
+ g_list_free(lengths);
+ return NULL;
+ }
+ }
+ bytes = read(fd, buffer, BUFF_SIZE);
+ }
+ ret_val = g_new(char, length + 1);
+ ret_val[length] = 0;
+ lengths_iterator = lengths;
+ list_iterator = list;
+ for ( ; list_iterator; list_iterator = list_iterator->next, lengths_iterator = lengths_iterator->next) {
+ int this_length = GPOINTER_TO_INT(lengths_iterator->data);
+ length -= this_length;
+ memcpy(ret_val + length, list_iterator->data, this_length);
+ }
+ close(fd);
+ g_list_foreach(list, (GFunc) g_free, NULL);
+ g_list_free(list);
+ g_list_free(lengths);
+ return ret_val;
+}