aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-logger.c
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2008-06-09 17:36:56 +0800
committerMilan Crha <mcrha@src.gnome.org>2008-06-09 17:36:56 +0800
commit4318006c1b3232589c73289267fca4573167db43 (patch)
tree11577833061e83a2f3c198ae3af6e4364794b7d9 /e-util/e-logger.c
parenteddb3f403bca1e490e0cd36d4451a93ab940edff (diff)
downloadgsoc2013-evolution-4318006c1b3232589c73289267fca4573167db43.tar
gsoc2013-evolution-4318006c1b3232589c73289267fca4573167db43.tar.gz
gsoc2013-evolution-4318006c1b3232589c73289267fca4573167db43.tar.bz2
gsoc2013-evolution-4318006c1b3232589c73289267fca4573167db43.tar.lz
gsoc2013-evolution-4318006c1b3232589c73289267fca4573167db43.tar.xz
gsoc2013-evolution-4318006c1b3232589c73289267fca4573167db43.tar.zst
gsoc2013-evolution-4318006c1b3232589c73289267fca4573167db43.zip
** Fix for bug #509595
2008-06-09 Milan Crha <mcrha@redhat.com> ** Fix for bug #509595 * e-logger.c: (e_logger_get_logs): Do not crash if file does not exists. Also be able to read lines more than 249 characters long. svn path=/trunk/; revision=35614
Diffstat (limited to 'e-util/e-logger.c')
-rw-r--r--e-util/e-logger.c44
1 files changed, 34 insertions, 10 deletions
diff --git a/e-util/e-logger.c b/e-util/e-logger.c
index a79793b045..9890cbd941 100644
--- a/e-util/e-logger.c
+++ b/e-util/e-logger.c
@@ -240,7 +240,6 @@ e_logger_get_logs (ELogger *logger,
{
FILE *fp;
gchar buf[250];
- gboolean error = FALSE;
g_return_if_fail (E_LOGGER (logger));
g_return_if_fail (func != NULL);
@@ -248,17 +247,42 @@ e_logger_get_logs (ELogger *logger,
/* Flush everything before we get the logs */
fflush (logger->priv->fp);
fp = g_fopen (logger->priv->logfile, "r");
- while (!error || feof(fp)) {
+
+ if (!fp) {
+ fprintf (stderr, "Cannot open log file '%s' for reading! No flush yet?\n", logger->priv->logfile ? logger->priv->logfile : "[null]");
+ return;
+ }
+
+ while (!feof (fp)) {
gchar *tmp;
- tmp = fgets (buf, 250, fp);
+ size_t len;
+
+ tmp = fgets (buf, sizeof (buf), fp);
if (!tmp)
break;
-#if 0
- if (strlen(tmp) == 249) {
- /* FIXME: There may be more */
- }
-#endif
- func (tmp, data);
+
+ len = strlen (tmp);
+ if (len > 0 && tmp [len - 1] != '\n' && !feof (fp)) {
+ /* there are more characters on a row than 249, so read them all */
+ GString *str = g_string_sized_new (1024);
+
+ g_string_append (str, tmp);
+
+ while (!feof (fp) && len > 0 && tmp [len - 1] != '\n') {
+ tmp = fgets (buf, sizeof (buf), fp);
+ if (!tmp)
+ break;
+
+ len = strlen (tmp);
+ g_string_append (str, tmp);
+ }
+
+ func (str->str, data);
+
+ g_string_free (str, TRUE);
+ } else
+ func (tmp, data);
}
- fclose(fp);
+
+ fclose (fp);
}