diff options
author | Christopher James Lahey <clahey@helixcode.com> | 2000-05-07 01:04:10 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2000-05-07 01:04:10 +0800 |
commit | 7453ffb6a86769bd22ce01da43fbbe919bef861d (patch) | |
tree | 7ae0da105d87b7bff10780700d9f9f83aa2a6959 /e-util | |
parent | 9b57702d4d406955ce3ec2e841253ed3efe3bbb8 (diff) | |
download | gsoc2013-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')
-rw-r--r-- | e-util/ChangeLog | 8 | ||||
-rw-r--r-- | e-util/e-html-utils.c | 3 | ||||
-rw-r--r-- | e-util/e-util.c | 52 | ||||
-rw-r--r-- | e-util/e-util.c-8611 | 52 | ||||
-rw-r--r-- | e-util/e-util.h | 1 | ||||
-rw-r--r-- | 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 <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. + 2000-05-03 Ettore Perazzoli <ettore@helixcode.com> * e-util.h: #include <glib.h> and <gtk/gtktypeutils.h>. 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 <danw@helixcode.com> * @@ -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 <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; +} 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; +} 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_ */ |