From 7453ffb6a86769bd22ce01da43fbbe919bef861d Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Sat, 6 May 2000 17:04:10 +0000 Subject: Got rid of some warnings. 2000-05-06 Christopher James Lahey * 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 --- e-util/ChangeLog | 8 ++++++++ e-util/e-html-utils.c | 3 +-- e-util/e-util.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ e-util/e-util.c-8611 | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ e-util/e-util.h | 1 + e-util/e-util.h-29002 | 1 + 6 files changed, 115 insertions(+), 2 deletions(-) diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 5a65629ce1..984739812c 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,11 @@ +2000-05-06 Christopher James Lahey + + * 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. + 2000-05-03 Ettore Perazzoli * e-util.h: #include and . diff --git a/e-util/e-html-utils.c b/e-util/e-html-utils.c index 8f872421d7..dc47d0243c 100644 --- a/e-util/e-html-utils.c +++ b/e-util/e-html-utils.c @@ -1,6 +1,5 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* e-html-utils.c -/* * Copyright (C) 2000 Helix Code, Inc. * Author: Dan Winship * @@ -135,7 +134,7 @@ e_text_to_html (const char *input, unsigned int flags) while (*cur) { if (isalpha (*cur) && (flags & E_TEXT_TO_HTML_CONVERT_URLS)) { - char *tmpurl = NULL, *refurl, *dispurl; + char *tmpurl = NULL, *refurl = NULL, *dispurl = NULL; if (!strncasecmp (cur, "http://", 7) || !strncasecmp (cur, "https://", 8) || diff --git a/e-util/e-util.c b/e-util/e-util.c index f2d787f37e..d5603d3dfa 100644 --- a/e-util/e-util.c +++ b/e-util/e-util.c @@ -22,6 +22,9 @@ #include #include +#include +#include +#include #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; +} 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 #include +#include +#include +#include #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; +} diff --git a/e-util/e-util.h b/e-util/e-util.h index a3380b9ea4..b8d49c9928 100644 --- a/e-util/e-util.h +++ b/e-util/e-util.h @@ -35,5 +35,6 @@ int g_str_compare(const void *x, const void *y); int g_int_compare(const void *x, const void *y); void e_free_object_list (GList *list); +char *e_read_file(const char *filename); #endif /* _E_UTIL_H_ */ diff --git a/e-util/e-util.h-29002 b/e-util/e-util.h-29002 index a3380b9ea4..b8d49c9928 100644 --- a/e-util/e-util.h-29002 +++ b/e-util/e-util.h-29002 @@ -35,5 +35,6 @@ int g_str_compare(const void *x, const void *y); int g_int_compare(const void *x, const void *y); void e_free_object_list (GList *list); +char *e_read_file(const char *filename); #endif /* _E_UTIL_H_ */ -- cgit v1.2.3